1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006
|
// Copyright (c) 2014-2020 Josh Blum
// Copyright (c) 2016-2016 Bastille Networks
// SPDX-License-Identifier: BSL-1.0
#include "ErrorHelpers.hpp"
#include "TypeHelpers.hpp"
#include <SoapySDR/Device.h>
#include <SoapySDR/Device.hpp>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath> //NAN
/*******************************************************************
* Error message implementation
******************************************************************/
#ifdef _MSC_VER
#define __thread __declspec(thread)
#endif
static __thread int lastErrorStatus;
static __thread char lastErrorMsg[1024];
void SoapySDRDevice_clearError(void)
{
lastErrorMsg[0] = '\0';
lastErrorStatus = 0;
}
int SoapySDRDevice_lastStatus(void)
{
return lastErrorStatus;
}
void SoapySDRDevice_reportError(const char *msg)
{
strncpy(lastErrorMsg, msg, sizeof(lastErrorMsg));
lastErrorMsg[sizeof(lastErrorMsg)-1] = '\0';
lastErrorStatus = -1;
}
const char *SoapySDRDevice_lastError(void)
{
return lastErrorMsg;
}
/*******************************************************************
* Error POD types
******************************************************************/
static const bool SoapySDRBoolErr = bool(-1);
static const SoapySDRRange SoapySDRRangeNAN = {NAN, NAN, 0.0};
static SoapySDRArgInfo SoapySDRArgInfoNull(void)
{
SoapySDRArgInfo info;
std::memset(&info, 0, sizeof(info));
return info;
}
/*******************************************************************
* Simple subclass definition for device
******************************************************************/
struct SoapySDRDevice : SoapySDR::Device {};
extern "C" {
/*******************************************************************
* Identification API
******************************************************************/
char *SoapySDRDevice_getDriverKey(const SoapySDRDevice *device)
{
__SOAPY_SDR_C_TRY
return toCString(device->getDriverKey());
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
char *SoapySDRDevice_getHardwareKey(const SoapySDRDevice *device)
{
__SOAPY_SDR_C_TRY
return toCString(device->getHardwareKey());
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
SoapySDRKwargs SoapySDRDevice_getHardwareInfo(const SoapySDRDevice *device)
{
__SOAPY_SDR_C_TRY
return toKwargs(device->getHardwareInfo());
__SOAPY_SDR_C_CATCH_RET(toKwargs(SoapySDR::Kwargs()));
}
/*******************************************************************
* Channels API
******************************************************************/
int SoapySDRDevice_setFrontendMapping(SoapySDRDevice *device, const int direction, const char *mapping)
{
__SOAPY_SDR_C_TRY
device->setFrontendMapping(direction, mapping);
__SOAPY_SDR_C_CATCH
}
char *SoapySDRDevice_getFrontendMapping(const SoapySDRDevice *device, const int direction)
{
__SOAPY_SDR_C_TRY
return toCString(device->getFrontendMapping(direction));
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
size_t SoapySDRDevice_getNumChannels(const SoapySDRDevice *device, const int direction)
{
__SOAPY_SDR_C_TRY
return device->getNumChannels(direction);
__SOAPY_SDR_C_CATCH_RET(std::string::npos);
}
SoapySDRKwargs SoapySDRDevice_getChannelInfo(const SoapySDRDevice *device, const int direction, const size_t channel)
{
__SOAPY_SDR_C_TRY
return toKwargs(device->getChannelInfo(direction, channel));
__SOAPY_SDR_C_CATCH_RET(toKwargs(SoapySDR::Kwargs()));
}
bool SoapySDRDevice_getFullDuplex(const SoapySDRDevice *device, const int direction, const size_t channel)
{
__SOAPY_SDR_C_TRY
return device->getFullDuplex(direction, channel);
__SOAPY_SDR_C_CATCH_RET(SoapySDRBoolErr);
}
/*******************************************************************
* Stream API
******************************************************************/
char **SoapySDRDevice_getStreamFormats(const SoapySDRDevice *device, const int direction, const size_t channel, size_t *length)
{
*length = 0;
__SOAPY_SDR_C_TRY
return toStrArray(device->getStreamFormats(direction, channel), length);
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
char *SoapySDRDevice_getNativeStreamFormat(const SoapySDRDevice *device, const int direction, const size_t channel, double *fullScale)
{
__SOAPY_SDR_C_TRY
return toCString(device->getNativeStreamFormat(direction, channel, *fullScale));
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
SoapySDRArgInfo *SoapySDRDevice_getStreamArgsInfo(const SoapySDRDevice *device, const int direction, const size_t channel, size_t *length)
{
*length = 0;
__SOAPY_SDR_C_TRY
return toArgInfoList(device->getStreamArgsInfo(direction, channel), length);
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
#undef SoapySDRDevice_setupStream
SoapySDRStream *SoapySDRDevice_setupStream(SoapySDRDevice *device, const int direction, const char *format, const size_t *channels, const size_t numChans, const SoapySDRKwargs *args)
{
__SOAPY_SDR_C_TRY
return reinterpret_cast<SoapySDRStream *>(device->setupStream(direction, format, std::vector<size_t>(channels, channels+numChans), toKwargs(args)));
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
int SoapySDRDevice_closeStream(SoapySDRDevice *device, SoapySDRStream *stream)
{
__SOAPY_SDR_C_TRY
device->closeStream(reinterpret_cast<SoapySDR::Stream *>(stream));
__SOAPY_SDR_C_CATCH
}
size_t SoapySDRDevice_getStreamMTU(const SoapySDRDevice *device, SoapySDRStream *stream)
{
__SOAPY_SDR_C_TRY
return device->getStreamMTU(reinterpret_cast<SoapySDR::Stream *>(stream));
__SOAPY_SDR_C_CATCH_RET(std::string::npos);
}
int SoapySDRDevice_activateStream(SoapySDRDevice *device,
SoapySDRStream *stream,
const int flags,
const long long timeNs,
const size_t numElems)
{
__SOAPY_SDR_C_TRY
return device->activateStream(reinterpret_cast<SoapySDR::Stream *>(stream), flags, timeNs, numElems);
__SOAPY_SDR_C_CATCH_RET(SOAPY_SDR_STREAM_ERROR);
}
int SoapySDRDevice_deactivateStream(SoapySDRDevice *device,
SoapySDRStream *stream,
const int flags,
const long long timeNs)
{
__SOAPY_SDR_C_TRY
return device->deactivateStream(reinterpret_cast<SoapySDR::Stream *>(stream), flags, timeNs);
__SOAPY_SDR_C_CATCH_RET(SOAPY_SDR_STREAM_ERROR);
}
int SoapySDRDevice_readStream(SoapySDRDevice *device, SoapySDRStream *stream, void * const *buffs, const size_t numElems, int *flags, long long *timeNs, const long timeoutUs)
{
__SOAPY_SDR_C_TRY
return device->readStream(reinterpret_cast<SoapySDR::Stream *>(stream), buffs, numElems, *flags, *timeNs, timeoutUs);
__SOAPY_SDR_C_CATCH_RET(SOAPY_SDR_STREAM_ERROR);
}
int SoapySDRDevice_writeStream(SoapySDRDevice *device, SoapySDRStream *stream, const void * const *buffs, const size_t numElems, int *flags, const long long timeNs, const long timeoutUs)
{
__SOAPY_SDR_C_TRY
return device->writeStream(reinterpret_cast<SoapySDR::Stream *>(stream), buffs, numElems, *flags, timeNs, timeoutUs);
__SOAPY_SDR_C_CATCH_RET(SOAPY_SDR_STREAM_ERROR);
}
int SoapySDRDevice_readStreamStatus(SoapySDRDevice *device, SoapySDRStream *stream, size_t *chanMask, int *flags, long long *timeNs, const long timeoutUs)
{
__SOAPY_SDR_C_TRY
return device->readStreamStatus(reinterpret_cast<SoapySDR::Stream *>(stream), *chanMask, *flags, *timeNs, timeoutUs);
__SOAPY_SDR_C_CATCH_RET(SOAPY_SDR_STREAM_ERROR);
}
/*******************************************************************
* Direct buffer access API
******************************************************************/
size_t SoapySDRDevice_getNumDirectAccessBuffers(SoapySDRDevice *device, SoapySDRStream *stream)
{
__SOAPY_SDR_C_TRY
return device->getNumDirectAccessBuffers(reinterpret_cast<SoapySDR::Stream *>(stream));
__SOAPY_SDR_C_CATCH_RET(std::string::npos);
}
int SoapySDRDevice_getDirectAccessBufferAddrs(SoapySDRDevice *device, SoapySDRStream *stream, const size_t handle, void **buffs)
{
__SOAPY_SDR_C_TRY
return device->getDirectAccessBufferAddrs(reinterpret_cast<SoapySDR::Stream *>(stream), handle, buffs);
__SOAPY_SDR_C_CATCH
}
int SoapySDRDevice_acquireReadBuffer(SoapySDRDevice *device,
SoapySDRStream *stream,
size_t *handle,
const void **buffs,
int *flags,
long long *timeNs,
const long timeoutUs)
{
__SOAPY_SDR_C_TRY
return device->acquireReadBuffer(reinterpret_cast<SoapySDR::Stream *>(stream), *handle, buffs, *flags, *timeNs, timeoutUs);
__SOAPY_SDR_C_CATCH_RET(SOAPY_SDR_STREAM_ERROR);
}
void SoapySDRDevice_releaseReadBuffer(SoapySDRDevice *device,
SoapySDRStream *stream,
const size_t handle)
{
__SOAPY_SDR_C_TRY
return device->releaseReadBuffer(reinterpret_cast<SoapySDR::Stream *>(stream), handle);
__SOAPY_SDR_C_CATCH_RET(SoapySDRVoidRet);
}
int SoapySDRDevice_acquireWriteBuffer(SoapySDRDevice *device,
SoapySDRStream *stream,
size_t *handle,
void **buffs,
const long timeoutUs)
{
__SOAPY_SDR_C_TRY
return device->acquireWriteBuffer(reinterpret_cast<SoapySDR::Stream *>(stream), *handle, buffs, timeoutUs);
__SOAPY_SDR_C_CATCH_RET(SOAPY_SDR_STREAM_ERROR);
}
void SoapySDRDevice_releaseWriteBuffer(SoapySDRDevice *device,
SoapySDRStream *stream,
const size_t handle,
const size_t numElems,
int *flags,
const long long timeNs)
{
__SOAPY_SDR_C_TRY
return device->releaseWriteBuffer(reinterpret_cast<SoapySDR::Stream *>(stream), handle, numElems, *flags, timeNs);
__SOAPY_SDR_C_CATCH_RET(SoapySDRVoidRet);
}
/*******************************************************************
* Antenna API
******************************************************************/
char **SoapySDRDevice_listAntennas(const SoapySDRDevice *device, const int direction, const size_t channel, size_t *length)
{
*length = 0;
__SOAPY_SDR_C_TRY
return toStrArray(device->listAntennas(direction, channel), length);
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
int SoapySDRDevice_setAntenna(SoapySDRDevice *device, const int direction, const size_t channel, const char *name)
{
__SOAPY_SDR_C_TRY
device->setAntenna(direction, channel, name);
__SOAPY_SDR_C_CATCH
}
char *SoapySDRDevice_getAntenna(const SoapySDRDevice *device, const int direction, const size_t channel)
{
__SOAPY_SDR_C_TRY
return toCString(device->getAntenna(direction, channel));
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
/*******************************************************************
* Frontend corrections API
******************************************************************/
bool SoapySDRDevice_hasDCOffsetMode(const SoapySDRDevice *device, const int direction, const size_t channel)
{
__SOAPY_SDR_C_TRY
return device->hasDCOffsetMode(direction, channel);
__SOAPY_SDR_C_CATCH_RET(SoapySDRBoolErr);
}
int SoapySDRDevice_setDCOffsetMode(SoapySDRDevice *device, const int direction, const size_t channel, const bool automatic)
{
__SOAPY_SDR_C_TRY
device->setDCOffsetMode(direction, channel, automatic);
__SOAPY_SDR_C_CATCH
}
bool SoapySDRDevice_getDCOffsetMode(const SoapySDRDevice *device, const int direction, const size_t channel)
{
__SOAPY_SDR_C_TRY
return device->getDCOffsetMode(direction, channel);
__SOAPY_SDR_C_CATCH_RET(SoapySDRBoolErr);
}
bool SoapySDRDevice_hasDCOffset(const SoapySDRDevice *device, const int direction, const size_t channel)
{
__SOAPY_SDR_C_TRY
return device->hasDCOffset(direction, channel);
__SOAPY_SDR_C_CATCH_RET(SoapySDRBoolErr);
}
int SoapySDRDevice_setDCOffset(SoapySDRDevice *device, const int direction, const size_t channel, const double offsetI, const double offsetQ)
{
__SOAPY_SDR_C_TRY
device->setDCOffset(direction, channel, std::complex<double>(offsetI, offsetQ));
__SOAPY_SDR_C_CATCH
}
int SoapySDRDevice_getDCOffset(const SoapySDRDevice *device, const int direction, const size_t channel, double *offsetI, double *offsetQ)
{
__SOAPY_SDR_C_TRY
std::complex<double> ret = device->getDCOffset(direction, channel);
*offsetI = ret.real();
*offsetQ = ret.imag();
__SOAPY_SDR_C_CATCH
}
bool SoapySDRDevice_hasIQBalance(const SoapySDRDevice *device, const int direction, const size_t channel)
{
__SOAPY_SDR_C_TRY
return device->hasIQBalance(direction, channel);
__SOAPY_SDR_C_CATCH_RET(SoapySDRBoolErr);
}
int SoapySDRDevice_setIQBalance(SoapySDRDevice *device, const int direction, const size_t channel, const double balanceI, const double balanceQ)
{
__SOAPY_SDR_C_TRY
device->setIQBalance(direction, channel, std::complex<double>(balanceI, balanceQ));
__SOAPY_SDR_C_CATCH
}
int SoapySDRDevice_getIQBalance(const SoapySDRDevice *device, const int direction, const size_t channel, double *balanceI, double *balanceQ)
{
__SOAPY_SDR_C_TRY
std::complex<double> ret = device->getIQBalance(direction, channel);
*balanceI = ret.real();
*balanceQ = ret.imag();
__SOAPY_SDR_C_CATCH
}
bool SoapySDRDevice_hasIQBalanceMode(const SoapySDRDevice *device, const int direction, const size_t channel)
{
__SOAPY_SDR_C_TRY
return device->hasIQBalanceMode(direction, channel);
__SOAPY_SDR_C_CATCH_RET(SoapySDRBoolErr);
}
int SoapySDRDevice_setIQBalanceMode(SoapySDRDevice *device, const int direction, const size_t channel, const bool automatic)
{
__SOAPY_SDR_C_TRY
device->setIQBalance(direction, channel, automatic);
__SOAPY_SDR_C_CATCH
}
bool SoapySDRDevice_getIQBalanceMode(const SoapySDRDevice *device, const int direction, const size_t channel)
{
__SOAPY_SDR_C_TRY
return device->getIQBalanceMode(direction, channel);
__SOAPY_SDR_C_CATCH_RET(SoapySDRBoolErr);
}
bool SoapySDRDevice_hasFrequencyCorrection(const SoapySDRDevice *device, const int direction, const size_t channel)
{
__SOAPY_SDR_C_TRY
return device->hasFrequencyCorrection(direction, channel);
__SOAPY_SDR_C_CATCH_RET(SoapySDRBoolErr);
}
int SoapySDRDevice_setFrequencyCorrection(SoapySDRDevice *device, const int direction, const size_t channel, const double value)
{
__SOAPY_SDR_C_TRY
device->setFrequencyCorrection(direction, channel, value);
__SOAPY_SDR_C_CATCH
}
double SoapySDRDevice_getFrequencyCorrection(const SoapySDRDevice *device, const int direction, const size_t channel)
{
__SOAPY_SDR_C_TRY
return device->getFrequencyCorrection(direction, channel);
__SOAPY_SDR_C_CATCH_RET(NAN);
}
/*******************************************************************
* Gain API
******************************************************************/
char **SoapySDRDevice_listGains(const SoapySDRDevice *device, const int direction, const size_t channel, size_t *length)
{
*length = 0;
__SOAPY_SDR_C_TRY
return toStrArray(device->listGains(direction, channel), length);
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
bool SoapySDRDevice_hasGainMode(const SoapySDRDevice *device, const int direction, const size_t channel)
{
__SOAPY_SDR_C_TRY
return device->hasGainMode(direction, channel);
__SOAPY_SDR_C_CATCH_RET(SoapySDRBoolErr);
}
int SoapySDRDevice_setGainMode(SoapySDRDevice *device, const int direction, const size_t channel, const bool automatic)
{
__SOAPY_SDR_C_TRY
device->setGainMode(direction, channel, automatic);
__SOAPY_SDR_C_CATCH
}
bool SoapySDRDevice_getGainMode(const SoapySDRDevice *device, const int direction, const size_t channel)
{
__SOAPY_SDR_C_TRY
return device->getGainMode(direction, channel);
__SOAPY_SDR_C_CATCH_RET(SoapySDRBoolErr);
}
int SoapySDRDevice_setGain(SoapySDRDevice *device, const int direction, const size_t channel, const double value)
{
__SOAPY_SDR_C_TRY
device->setGain(direction, channel, value);
__SOAPY_SDR_C_CATCH
}
int SoapySDRDevice_setGainElement(SoapySDRDevice *device, const int direction, const size_t channel, const char *name, const double value)
{
__SOAPY_SDR_C_TRY
device->setGain(direction, channel, name, value);
__SOAPY_SDR_C_CATCH
}
double SoapySDRDevice_getGain(const SoapySDRDevice *device, const int direction, const size_t channel)
{
__SOAPY_SDR_C_TRY
return device->getGain(direction, channel);
__SOAPY_SDR_C_CATCH_RET(NAN);
}
double SoapySDRDevice_getGainElement(const SoapySDRDevice *device, const int direction, const size_t channel, const char *name)
{
__SOAPY_SDR_C_TRY
return device->getGain(direction, channel, name);
__SOAPY_SDR_C_CATCH_RET(NAN);
}
SoapySDRRange SoapySDRDevice_getGainRange(const SoapySDRDevice *device, const int direction, const size_t channel)
{
__SOAPY_SDR_C_TRY
return toRange(device->getGainRange(direction, channel));
__SOAPY_SDR_C_CATCH_RET(SoapySDRRangeNAN);
}
SoapySDRRange SoapySDRDevice_getGainElementRange(const SoapySDRDevice *device, const int direction, const size_t channel, const char *name)
{
__SOAPY_SDR_C_TRY
return toRange(device->getGainRange(direction, channel, name));
__SOAPY_SDR_C_CATCH_RET(SoapySDRRangeNAN);
}
/*******************************************************************
* Frequency API
******************************************************************/
int SoapySDRDevice_setFrequency(SoapySDRDevice *device, const int direction, const size_t channel, const double frequency, const SoapySDRKwargs *args)
{
__SOAPY_SDR_C_TRY
device->setFrequency(direction, channel, frequency, toKwargs(args));
__SOAPY_SDR_C_CATCH
}
int SoapySDRDevice_setFrequencyComponent(SoapySDRDevice *device, const int direction, const size_t channel, const char *name, const double frequency, const SoapySDRKwargs *args)
{
__SOAPY_SDR_C_TRY
device->setFrequency(direction, channel, name, frequency, toKwargs(args));
__SOAPY_SDR_C_CATCH
}
double SoapySDRDevice_getFrequency(const SoapySDRDevice *device, const int direction, const size_t channel)
{
__SOAPY_SDR_C_TRY
return device->getFrequency(direction, channel);
__SOAPY_SDR_C_CATCH_RET(NAN);
}
double SoapySDRDevice_getFrequencyComponent(const SoapySDRDevice *device, const int direction, const size_t channel, const char *name)
{
__SOAPY_SDR_C_TRY
return device->getFrequency(direction, channel, name);
__SOAPY_SDR_C_CATCH_RET(NAN);
}
char **SoapySDRDevice_listFrequencies(const SoapySDRDevice *device, const int direction, const size_t channel, size_t *length)
{
*length = 0;
__SOAPY_SDR_C_TRY
return toStrArray(device->listFrequencies(direction, channel), length);
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
SoapySDRRange *SoapySDRDevice_getFrequencyRange(const SoapySDRDevice *device, const int direction, const size_t channel, size_t *length)
{
*length = 0;
__SOAPY_SDR_C_TRY
return toRangeList(device->getFrequencyRange(direction, channel), length);
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
SoapySDRRange *SoapySDRDevice_getFrequencyRangeComponent(const SoapySDRDevice *device, const int direction, const size_t channel, const char *name, size_t *length)
{
*length = 0;
__SOAPY_SDR_C_TRY
return toRangeList(device->getFrequencyRange(direction, channel, name), length);
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
SoapySDRArgInfo *SoapySDRDevice_getFrequencyArgsInfo(const SoapySDRDevice *device, const int direction, const size_t channel, size_t *length)
{
*length = 0;
__SOAPY_SDR_C_TRY
return toArgInfoList(device->getFrequencyArgsInfo(direction, channel), length);
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
/*******************************************************************
* Sample Rate API
******************************************************************/
int SoapySDRDevice_setSampleRate(SoapySDRDevice *device, const int direction, const size_t channel, const double rate)
{
__SOAPY_SDR_C_TRY
device->setSampleRate(direction, channel, rate);
__SOAPY_SDR_C_CATCH
}
double SoapySDRDevice_getSampleRate(const SoapySDRDevice *device, const int direction, const size_t channel)
{
__SOAPY_SDR_C_TRY
return device->getSampleRate(direction, channel);
__SOAPY_SDR_C_CATCH_RET(NAN);
}
double *SoapySDRDevice_listSampleRates(const SoapySDRDevice *device, const int direction, const size_t channel, size_t *length)
{
*length = 0;
__SOAPY_SDR_C_TRY
return toNumericList(device->listSampleRates(direction, channel), length);
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
SoapySDRRange *SoapySDRDevice_getSampleRateRange(const SoapySDRDevice *device, const int direction, const size_t channel, size_t *length)
{
*length = 0;
__SOAPY_SDR_C_TRY
return toRangeList(device->getSampleRateRange(direction, channel), length);
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
/*******************************************************************
* Bandwidth API
******************************************************************/
int SoapySDRDevice_setBandwidth(SoapySDRDevice *device, const int direction, const size_t channel, const double bw)
{
__SOAPY_SDR_C_TRY
device->setBandwidth(direction, channel, bw);
__SOAPY_SDR_C_CATCH
}
double SoapySDRDevice_getBandwidth(const SoapySDRDevice *device, const int direction, const size_t channel)
{
__SOAPY_SDR_C_TRY
return device->getBandwidth(direction, channel);
__SOAPY_SDR_C_CATCH_RET(NAN);
}
double *SoapySDRDevice_listBandwidths(const SoapySDRDevice *device, const int direction, const size_t channel, size_t *length)
{
*length = 0;
__SOAPY_SDR_C_TRY
return toNumericList(device->listBandwidths(direction, channel), length);
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
SoapySDRRange *SoapySDRDevice_getBandwidthRange(const SoapySDRDevice *device, const int direction, const size_t channel, size_t *length)
{
*length = 0;
__SOAPY_SDR_C_TRY
return toRangeList(device->getBandwidthRange(direction, channel), length);
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
/*******************************************************************
* Clocking API
******************************************************************/
int SoapySDRDevice_setMasterClockRate(SoapySDRDevice *device, const double rate)
{
__SOAPY_SDR_C_TRY
device->setMasterClockRate(rate);
__SOAPY_SDR_C_CATCH
}
double SoapySDRDevice_getMasterClockRate(const SoapySDRDevice *device)
{
__SOAPY_SDR_C_TRY
return device->getMasterClockRate();
__SOAPY_SDR_C_CATCH_RET(NAN);
}
SoapySDRRange *SoapySDRDevice_getMasterClockRates(const SoapySDRDevice *device, size_t *length)
{
*length = 0;
__SOAPY_SDR_C_TRY
return toRangeList(device->getMasterClockRates(), length);
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
int SoapySDRDevice_setReferenceClockRate(SoapySDRDevice *device, const double rate)
{
__SOAPY_SDR_C_TRY
device->setReferenceClockRate(rate);
__SOAPY_SDR_C_CATCH
}
double SoapySDRDevice_getReferenceClockRate(const SoapySDRDevice *device)
{
__SOAPY_SDR_C_TRY
return device->getReferenceClockRate();
__SOAPY_SDR_C_CATCH_RET(NAN);
}
SoapySDRRange *SoapySDRDevice_getReferenceClockRates(const SoapySDRDevice *device, size_t *length)
{
*length = 0;
__SOAPY_SDR_C_TRY
return toRangeList(device->getReferenceClockRates(), length);
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
char **SoapySDRDevice_listClockSources(const SoapySDRDevice *device, size_t *length)
{
*length = 0;
__SOAPY_SDR_C_TRY
return toStrArray(device->listClockSources(), length);
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
int SoapySDRDevice_setClockSource(SoapySDRDevice *device, const char *source)
{
__SOAPY_SDR_C_TRY
device->setClockSource(source);
__SOAPY_SDR_C_CATCH
}
char *SoapySDRDevice_getClockSource(const SoapySDRDevice *device)
{
__SOAPY_SDR_C_TRY
return toCString(device->getClockSource());
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
/*******************************************************************
* Time API
******************************************************************/
char **SoapySDRDevice_listTimeSources(const SoapySDRDevice *device, size_t *length)
{
*length = 0;
__SOAPY_SDR_C_TRY
return toStrArray(device->listTimeSources(), length);
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
int SoapySDRDevice_setTimeSource(SoapySDRDevice *device, const char *source)
{
__SOAPY_SDR_C_TRY
device->setTimeSource(source);
__SOAPY_SDR_C_CATCH
}
char *SoapySDRDevice_getTimeSource(const SoapySDRDevice *device)
{
__SOAPY_SDR_C_TRY
return toCString(device->getTimeSource());
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
bool SoapySDRDevice_hasHardwareTime(const SoapySDRDevice *device, const char *what)
{
__SOAPY_SDR_C_TRY
return device->hasHardwareTime(what);
__SOAPY_SDR_C_CATCH_RET(SoapySDRBoolErr);
}
long long SoapySDRDevice_getHardwareTime(const SoapySDRDevice *device, const char *what)
{
__SOAPY_SDR_C_TRY
return device->getHardwareTime(what);
__SOAPY_SDR_C_CATCH
}
int SoapySDRDevice_setHardwareTime(SoapySDRDevice *device, const long long timeNs, const char *what)
{
__SOAPY_SDR_C_TRY
device->setHardwareTime(timeNs, what);
__SOAPY_SDR_C_CATCH
}
int SoapySDRDevice_setCommandTime(SoapySDRDevice *device, const long long timeNs, const char *what)
{
__SOAPY_SDR_C_TRY
device->setCommandTime(timeNs, what);
__SOAPY_SDR_C_CATCH
}
/*******************************************************************
* Sensor API
******************************************************************/
char **SoapySDRDevice_listSensors(const SoapySDRDevice *device, size_t *length)
{
*length = 0;
__SOAPY_SDR_C_TRY
return toStrArray(device->listSensors(), length);
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
SoapySDRArgInfo SoapySDRDevice_getSensorInfo(const SoapySDRDevice *device, const char *key)
{
__SOAPY_SDR_C_TRY
return toArgInfo(device->getSensorInfo(key));
__SOAPY_SDR_C_CATCH_RET(SoapySDRArgInfoNull());
}
char *SoapySDRDevice_readSensor(const SoapySDRDevice *device, const char *key)
{
__SOAPY_SDR_C_TRY
return toCString(device->readSensor(key));
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
char **SoapySDRDevice_listChannelSensors(const SoapySDRDevice *device, const int direction, const size_t channel, size_t *length)
{
*length = 0;
__SOAPY_SDR_C_TRY
return toStrArray(device->listSensors(direction, channel), length);
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
SoapySDRArgInfo SoapySDRDevice_getChannelSensorInfo(const SoapySDRDevice *device, const int direction, const size_t channel, const char *key)
{
__SOAPY_SDR_C_TRY
return toArgInfo(device->getSensorInfo(direction, channel, key));
__SOAPY_SDR_C_CATCH_RET(SoapySDRArgInfoNull());
}
char *SoapySDRDevice_readChannelSensor(const SoapySDRDevice *device, const int direction, const size_t channel, const char *key)
{
__SOAPY_SDR_C_TRY
return toCString(device->readSensor(direction, channel, key));
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
/*******************************************************************
* Register API
******************************************************************/
char **SoapySDRDevice_listRegisterInterfaces(const SoapySDRDevice *device, size_t *length)
{
*length = 0;
__SOAPY_SDR_C_TRY
return toStrArray(device->listRegisterInterfaces(), length);
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
int SoapySDRDevice_writeRegister(SoapySDRDevice *device, const char *name, const unsigned addr, const unsigned value)
{
__SOAPY_SDR_C_TRY
device->writeRegister(name, addr, value);
__SOAPY_SDR_C_CATCH
}
unsigned SoapySDRDevice_readRegister(const SoapySDRDevice *device, const char *name, const unsigned addr)
{
__SOAPY_SDR_C_TRY
return device->readRegister(name, addr);
__SOAPY_SDR_C_CATCH
}
int SoapySDRDevice_writeRegisters(SoapySDRDevice *device, const char *name, const unsigned addr, const unsigned *value, const size_t length)
{
__SOAPY_SDR_C_TRY
device->writeRegisters(name, addr, toNumericVector(value, length));
__SOAPY_SDR_C_CATCH
}
unsigned *SoapySDRDevice_readRegisters(const SoapySDRDevice *device, const char *name, const unsigned addr, size_t *length)
{
const size_t inputLen = *length;
*length = 0; //clear in case of error
__SOAPY_SDR_C_TRY
return toNumericList(device->readRegisters(name, addr, inputLen), length);
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
/*******************************************************************
* Settings API
******************************************************************/
SoapySDRArgInfo *SoapySDRDevice_getSettingInfo(const SoapySDRDevice *device, size_t *length)
{
*length = 0;
__SOAPY_SDR_C_TRY
return toArgInfoList(device->getSettingInfo(), length);
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
int SoapySDRDevice_writeSetting(SoapySDRDevice *device, const char *key, const char *value)
{
__SOAPY_SDR_C_TRY
device->writeSetting(key, value);
__SOAPY_SDR_C_CATCH
}
char *SoapySDRDevice_readSetting(const SoapySDRDevice *device, const char *key)
{
__SOAPY_SDR_C_TRY
return toCString(device->readSetting(key));
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
SoapySDRArgInfo *SoapySDRDevice_getChannelSettingInfo(const SoapySDRDevice *device, const int direction, const size_t channel, size_t *length)
{
*length = 0;
__SOAPY_SDR_C_TRY
return toArgInfoList(device->getSettingInfo(direction, channel), length);
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
int SoapySDRDevice_writeChannelSetting(SoapySDRDevice *device, const int direction, const size_t channel, const char *key, const char *value)
{
__SOAPY_SDR_C_TRY
device->writeSetting(direction, channel, key, value);
__SOAPY_SDR_C_CATCH
}
char *SoapySDRDevice_readChannelSetting(const SoapySDRDevice *device, const int direction, const size_t channel, const char *key)
{
__SOAPY_SDR_C_TRY
return toCString(device->readSetting(direction, channel, key));
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
/*******************************************************************
* GPIO API
******************************************************************/
char **SoapySDRDevice_listGPIOBanks(const SoapySDRDevice *device, size_t *length)
{
*length = 0;
__SOAPY_SDR_C_TRY
return toStrArray(device->listGPIOBanks(), length);
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
int SoapySDRDevice_writeGPIO(SoapySDRDevice *device, const char *bank, const unsigned value)
{
__SOAPY_SDR_C_TRY
device->writeGPIO(bank, value);
__SOAPY_SDR_C_CATCH
}
int SoapySDRDevice_writeGPIOMasked(SoapySDRDevice *device, const char *bank, const unsigned value, const unsigned mask)
{
__SOAPY_SDR_C_TRY
device->writeGPIO(bank, value, mask);
__SOAPY_SDR_C_CATCH
}
unsigned SoapySDRDevice_readGPIO(const SoapySDRDevice *device, const char *bank)
{
__SOAPY_SDR_C_TRY
return device->readGPIO(bank);
__SOAPY_SDR_C_CATCH
}
int SoapySDRDevice_writeGPIODir(SoapySDRDevice *device, const char *bank, const unsigned dir)
{
__SOAPY_SDR_C_TRY
device->writeGPIODir(bank, dir);
__SOAPY_SDR_C_CATCH
}
int SoapySDRDevice_writeGPIODirMasked(SoapySDRDevice *device, const char *bank, const unsigned dir, const unsigned mask)
{
__SOAPY_SDR_C_TRY
device->writeGPIODir(bank, dir, mask);
__SOAPY_SDR_C_CATCH
}
unsigned SoapySDRDevice_readGPIODir(const SoapySDRDevice *device, const char *bank)
{
__SOAPY_SDR_C_TRY
return device->readGPIODir(bank);
__SOAPY_SDR_C_CATCH
}
/*******************************************************************
* I2C API
******************************************************************/
int SoapySDRDevice_writeI2C(SoapySDRDevice *device, const int addr, const char *data, const size_t numBytes)
{
__SOAPY_SDR_C_TRY
device->writeI2C(addr, std::string(data, numBytes));
__SOAPY_SDR_C_CATCH
}
char *SoapySDRDevice_readI2C(SoapySDRDevice *device, const int addr, size_t *numBytes)
{
const size_t inputNumBytes = *numBytes;
*numBytes = 0; //clear in case of error
__SOAPY_SDR_C_TRY
const auto bytes = device->readI2C(addr, inputNumBytes);
char *buff = callocArrayType<char>(bytes.size());
std::copy(bytes.begin(), bytes.end(), buff);
*numBytes = bytes.size();
return buff;
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
/*******************************************************************
* SPI API
******************************************************************/
unsigned SoapySDRDevice_transactSPI(SoapySDRDevice *device, const int addr, const unsigned data, const size_t numBits)
{
__SOAPY_SDR_C_TRY
return device->transactSPI(addr, data, numBits);
__SOAPY_SDR_C_CATCH
}
/*******************************************************************
* UART API
******************************************************************/
char **SoapySDRDevice_listUARTs(const SoapySDRDevice *device, size_t *length)
{
*length = 0;
__SOAPY_SDR_C_TRY
return toStrArray(device->listUARTs(), length);
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
int SoapySDRDevice_writeUART(SoapySDRDevice *device, const char *which, const char *data)
{
__SOAPY_SDR_C_TRY
device->writeUART(which, data);
__SOAPY_SDR_C_CATCH
}
char *SoapySDRDevice_readUART(const SoapySDRDevice *device, const char *which, const long timeoutUs)
{
__SOAPY_SDR_C_TRY
return toCString(device->readUART(which, timeoutUs));
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
/*******************************************************************
* Native Access API
******************************************************************/
void* SoapySDRDevice_getNativeDeviceHandle(const SoapySDRDevice *device)
{
__SOAPY_SDR_C_TRY
return device->getNativeDeviceHandle();
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
} //extern "C"
|