summaryrefslogtreecommitdiff
path: root/packages/python/python-formencode/.mtn2git_empty
blob: e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 (plain)

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
/*
 / _____)             _              | |
( (____  _____ ____ _| |_ _____  ____| |__
 \____ \| ___ |    (_   _) ___ |/ ___)  _ \
 _____) ) ____| | | || |_| ____( (___| | | |
(______/|_____)_|_|_| \__)_____)\____)_| |_|
  (C)2013 Semtech-Cycleo

Description:
    Send a bunch of packets on a settable frequency

License: Revised BSD License, see LICENSE.TXT file include in the project
Maintainer: Sylvain Miermont
*/


/* -------------------------------------------------------------------------- */
/* --- DEPENDANCIES --------------------------------------------------------- */

/* fix an issue between POSIX and C99 */
#if __STDC_VERSION__ >= 199901L
    #define _XOPEN_SOURCE 600
#else
    #define _XOPEN_SOURCE 500
#endif

#include <stdint.h>     /* C99 types */
#include <stdbool.h>    /* bool type */
#include <stdio.h>      /* printf fprintf sprintf fopen fputs */

#include <string.h>     /* memset */
#include <signal.h>     /* sigaction */
#include <unistd.h>     /* getopt access */
#include <stdlib.h>     /* exit codes */
#include <getopt.h>     /* getopt_long */

#include "loragw_hal.h"
#include "loragw_reg.h"
#include "loragw_aux.h"
#include "loragw_spi.h"

/* -------------------------------------------------------------------------- */
/* --- PRIVATE MACROS ------------------------------------------------------- */

#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
#define MSG(args...) fprintf(stderr, args) /* message that is destined to the user */

/* -------------------------------------------------------------------------- */
/* --- PRIVATE CONSTANTS ---------------------------------------------------- */

#define TX_RF_CHAIN                 0 /* TX only supported on radio A */
#define DEFAULT_RSSI_OFFSET         0.0
#define DEFAULT_MODULATION          "LORA"
#define DEFAULT_BR_KBPS             50
#define DEFAULT_FDEV_KHZ            25
#define DEFAULT_NOTCH_FREQ          129000U /* 129 kHz */
#define DEFAULT_SX127X_RSSI_OFFSET  -4 /* dB */

/* -------------------------------------------------------------------------- */
/* --- PRIVATE VARIABLES (GLOBAL) ------------------------------------------- */

/* signal handling variables */
struct sigaction sigact; /* SIGQUIT&SIGINT&SIGTERM signal handling */
static int exit_sig = 0; /* 1 -> application terminates cleanly (shut down hardware, close open files, etc) */
static int quit_sig = 0; /* 1 -> application terminates without shutting down the hardware */

/* TX gain LUT table */
static struct lgw_tx_gain_lut_s txgain_lut = {
    .size = 5,
    .lut[0] = {
        .dig_gain = 0,
        .pa_gain = 0,
        .dac_gain = 3,
        .mix_gain = 12,
        .rf_power = 0
    },
    .lut[1] = {
        .dig_gain = 0,
        .pa_gain = 1,
        .dac_gain = 3,
        .mix_gain = 12,
        .rf_power = 10
    },
    .lut[2] = {
        .dig_gain = 0,
        .pa_gain = 2,
        .dac_gain = 3,
        .mix_gain = 10,
        .rf_power = 14
    },
    .lut[3] = {
        .dig_gain = 0,
        .pa_gain = 3,
        .dac_gain = 3,
        .mix_gain = 9,
        .rf_power = 20
    },
    .lut[4] = {
        .dig_gain = 0,
        .pa_gain = 3,
        .dac_gain = 3,
        .mix_gain = 14,
        .rf_power = 27
    }};

/* -------------------------------------------------------------------------- */
/* --- PRIVATE FUNCTIONS DECLARATION ---------------------------------------- */

static void sig_handler(int sigio);

void usage (void);

/* -------------------------------------------------------------------------- */
/* --- PRIVATE FUNCTIONS DEFINITION ----------------------------------------- */

static void sig_handler(int sigio) {
    if (sigio == SIGQUIT) {
        quit_sig = 1;;
    } else if ((sigio == SIGINT) || (sigio == SIGTERM)) {
        exit_sig = 1;
    }
}

/* describe command line options */
void usage(void) {
    int i;

    printf("*** Library version information ***\n%s\n\n", lgw_version_info());
    printf("Available options:\n");
    printf(" -h                 print this help\n");
    printf(" -r         <int>   radio type (SX1255:1255, SX1257:1257)\n");
    printf(" -n         <uint>  TX notch filter frequency in kHz [126..250]\n");
    printf(" -f         <float> target frequency in MHz\n");
    printf(" -k         <uint>  concentrator clock source (0:Radio A, 1:Radio B)\n");
    printf(" -m         <str>   modulation type ['LORA', 'FSK']\n");
    printf(" -b         <uint>  LoRa bandwidth in kHz [125, 250, 500]\n");
    printf(" -s         <uint>  LoRa Spreading Factor [7-12]\n");
    printf(" -c         <uint>  LoRa Coding Rate [1-4]\n");
    printf(" -d         <uint>  FSK frequency deviation in kHz [1:250]\n");
    printf(" -q         <float> FSK bitrate in kbps [0.5:250]\n");
    printf(" -p         <int>   RF power (dBm) [ ");
    for (i = 0; i < txgain_lut.size; i++) {
        printf("%ddBm ", txgain_lut.lut[i].rf_power);
    }
    printf("]\n");
    printf(" -l         <uint>  LoRa preamble length (symbols)\n");
    printf(" -z         <uint>  payload size (bytes, <256)\n");
    printf(" -i                 send packet using inverted modulation polarity\n");
    printf(" -t         <uint>  pause between packets (ms)\n");
    printf(" -x         <int>   nb of times the sequence is repeated (-1 loop until stopped)\n");
    printf(" --lbt-freq         <float>  lbt first channel frequency in MHz\n");
    printf(" --lbt-nbch         <uint>   lbt number of channels [1..8]\n");
    printf(" --lbt-sctm         <uint>   lbt scan time in usec to be applied to all channels [128, 5000]\n");
    printf(" --lbt-rssi         <int>    lbt rssi target in dBm [-128..0]\n");
    printf(" --lbt-rssi-offset  <int>    rssi offset in dB to be applied to SX127x RSSI [-128..127]\n");
    printf(" --pa               <uint>   pa gain\n");
    printf(" --mix              <uint>   mix gain\n");
    printf(" --dig              <uint>   dig gain\n");
    printf(" --dac              <uint>   dac gain\n");
    printf(" --path             <string> path of SPIDEV e.g. /dev/spidev0.0\n");
}

/* -------------------------------------------------------------------------- */
/* --- MAIN FUNCTION -------------------------------------------------------- */

int main(int argc, char **argv)
{
    int i;
    uint8_t status_var;

    /* user entry parameters */
    int xi = 0;
    unsigned int xu = 0;
    double xd = 0.0;
    float xf = 0.0;
    char arg_s[64];

    /* application parameters */
    char mod[64] = DEFAULT_MODULATION;
    uint32_t f_target = 0; /* target frequency - invalid default value, has to be specified by user */
    int sf = 10; /* SF10 by default */
    int cr = 1; /* CR1 aka 4/5 by default */
    int bw = 125; /* 125kHz bandwidth by default */
    int pow = 14; /* 14 dBm by default */
    int preamb = 8; /* 8 symbol preamble by default */
    int pl_size = 16; /* 16 bytes payload by default */
    int delay = 1000; /* 1 second between packets by default */
    int repeat = -1; /* by default, repeat until stopped */
    bool invert = false;
    float br_kbps = DEFAULT_BR_KBPS;
    uint8_t fdev_khz = DEFAULT_FDEV_KHZ;
    bool lbt_enable = false;
    uint32_t lbt_f_target = 0;
    uint32_t lbt_sc_time = 5000;
    int8_t lbt_rssi_target_dBm = -80;
    int8_t lbt_rssi_offset_dB = DEFAULT_SX127X_RSSI_OFFSET;
    uint8_t  lbt_nb_channel = 1;
    uint32_t sx1301_count_us;
    uint32_t tx_notch_freq = DEFAULT_NOTCH_FREQ;
    bool force_tx_lut = false;
    uint8_t dig_gain = 0;   /*!> 2 bits, control of the digital gain of SX1301 */
    uint8_t pa_gain = 0;    /*!> 2 bits, control of the external PA (SX1301 I/O) */
    uint8_t dac_gain = 3;   /*!> 2 bits, control of the radio DAC */
    uint8_t mix_gain = 0;   /*!> 4 bits, control of the radio mixer */

    /* RF configuration (TX fail if RF chain is not enabled) */
    enum lgw_radio_type_e radio_type = LGW_RADIO_TYPE_NONE;
    uint8_t clocksource = 0; /* Radio B is source by default */
    struct lgw_conf_board_s boardconf;
    struct lgw_conf_lbt_s lbtconf;
    struct lgw_conf_rxrf_s rfconf;

    /* allocate memory for packet sending */
    struct lgw_pkt_tx_s txpkt; /* array containing 1 outbound packet + metadata */

    /* loop variables (also use as counters in the packet payload) */
    uint16_t cycle_count = 0;

    /* Parameter parsing */
    int option_index = 0;
    static struct option long_options[] = {
        {"lbt-freq", required_argument, 0, 0},
        {"lbt-sctm", required_argument, 0, 0},
        {"lbt-rssi", required_argument, 0, 0},
        {"lbt-nbch", required_argument, 0, 0},
        {"lbt-rssi-offset", required_argument, 0, 0},
        {"path", required_argument, 0, 0},
        {"pa", required_argument, 0, 0},
        {"mix", required_argument, 0, 0},
        {"dig", required_argument, 0, 0},
        {"dac", required_argument, 0, 0},
        {0, 0, 0, 0}
    };

    /* parse command line options */
    while ((i = getopt_long (argc, argv, "hif:n:m:b:s:c:p:l:z:t:x:r:k:d:q:", long_options, &option_index)) != -1) {
        switch (i) {
            case 'h':
                usage();
                return EXIT_FAILURE;
                break;

            case 'f': /* <float> Target frequency in MHz */
                i = sscanf(optarg, "%lf", &xd);
                if ((i != 1) || (xd < 30.0) || (xd > 3000.0)) {
                    MSG("ERROR: invalid TX frequency\n");
                    usage();
                    return EXIT_FAILURE;
                } else {
                    f_target = (uint32_t)((xd*1e6) + 0.5); /* .5 Hz offset to get rounding instead of truncating */
                }
                break;

            case 'n': /* <uint> TX notch filter frequency in kHz */
                i = sscanf(optarg, "%i", &xi);
                if ((i != 1) || ((xi < 126) || (xi > 250))) {
                    MSG("ERROR: invalid TX notch filter frequency\n");
                    usage();
                    return EXIT_FAILURE;
                } else {
                    tx_notch_freq = xi*1000;
                }
                break;

            case 'm': /* <str> Modulation type */
                i = sscanf(optarg, "%s", arg_s);
                if ((i != 1) || ((strcmp(arg_s,"LORA") != 0) && (strcmp(arg_s,"FSK")))) {
                    MSG("ERROR: invalid modulation type\n");
                    usage();
                    return EXIT_FAILURE;
                } else {
                    sprintf(mod, "%s", arg_s);
                }
                break;

            case 'b': /* <int> Modulation bandwidth in kHz */
                i = sscanf(optarg, "%i", &xi);
                if ((i != 1) || ((xi != 125) && (xi