Date:2013-02-13 00:07:21 (6 years 8 months ago)
Author:Werner Almesberger
Commit:c19fccf17c2f6f7bee9f59dddf8ef607df41ccf1
Message:tools/atrf-txrx/atrf-txrx.c: new option -R for RTT measurement mode

This is similar to ping (-P) but separates roles more clearly and
collects timing statistics instead of visualizing reception.
Files: tools/atrf-txrx/atrf-txrx.c (12 diffs)

Change Details

tools/atrf-txrx/atrf-txrx.c
6767    mode_hmac,
6868    mode_per,
6969    mode_ping,
70    mode_rtt,
7071    mode_cont_tx,
7172};
7273
...... 
452453}
453454
454455
456/* ----- Round-trip time --------------------------------------------------- */
457
458
459static void rtt_slave(struct atrf_dsc *dsc)
460{
461    uint8_t buf[MAX_PSDU];
462    int n;
463
464    while (run) {
465        atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_RX_ON);
466        wait_for_interrupt(dsc, IRQ_TRX_END,
467            IRQ_TRX_END | IRQ_RX_START | IRQ_PLL_LOCK | IRQ_AMI, 0);
468        if (!run)
469            break;
470        n = atrf_buf_read(dsc, buf, sizeof(buf));
471        if (n < 0)
472            exit(1);
473        if (n < 2) {
474            fprintf(stderr, "%d bytes received\n", n);
475            continue;
476        }
477        atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_PLL_ON);
478        atrf_buf_write(dsc, buf, n);
479        atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TX_START);
480        wait_for_interrupt(dsc, IRQ_TRX_END,
481            IRQ_TRX_END | IRQ_PLL_LOCK, 10);
482    }
483}
484
485
486static void rtt_master(struct atrf_dsc *dsc, int packets, int size)
487{
488    uint8_t buf[size+2]; /* +CRC */
489    struct timeval t0, t1;
490    uint8_t irq;
491    int first = 1;
492    double min = 0, max = 0, sum = 0, sum2 = 0, d;
493    int lost = 0, n;
494    int i;
495
496    memset(buf, 0, size+2);
497    for (i = 0; i != packets; i++) {
498        atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_PLL_ON);
499        atrf_buf_write(dsc, buf, size+2);
500        gettimeofday(&t0, NULL);
501        atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TX_START);
502        wait_for_interrupt(dsc, IRQ_TRX_END,
503            IRQ_TRX_END | IRQ_PLL_LOCK, 10);
504        atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_RX_ON);
505        irq = wait_for_interrupt(dsc, IRQ_TRX_END,
506            IRQ_TRX_END | IRQ_RX_START | IRQ_PLL_LOCK | IRQ_AMI, 1000);
507        if (irq) {
508            gettimeofday(&t1, NULL);
509            d = t1.tv_sec-t0.tv_sec+(t1.tv_usec-t0.tv_usec)*1e-6;
510            sum += d;
511            sum2 += d*d;
512            if (first || d < min)
513                min = d;
514            if (first || d > max)
515                max = d;
516            first = 0;
517            n = atrf_buf_read(dsc, buf, size);
518            if (n != size)
519                fprintf(stderr, "%d bytes received\n", n);
520        } else {
521            lost++;
522        }
523    }
524    n = packets-lost;
525    printf("%d sent, %d received, %d lost (%g%%)\n",
526        packets, n, lost, lost*100.0/packets);
527    if (n)
528        printf("rtt min/avg/max = %.3f/%.3f/%.3f ms, mdev = %.3f ms\n",
529            min*1000.0, sum*1000.0/n, max*1000.0,
530            sqrt((sum2-sum*sum/n)/n)*1000.0);
531}
532
533
455534/* ----- Continuous wave test ---------------------------------------------- */
456535
457536
...... 
490569" %s [common_options] -H [message]\n"
491570" %s [common_options] -E pause_s [repetitions]\n"
492571" %s [common_options] -P [max_wait_s]\n"
572" %s [common_options] -R [packets size]\n"
493573" %s [common_options] -T offset [command]\n\n"
494574" text message mode:\n"
495575" message message string to send (if absent, receive)\n"
...... 
503583" Ping-pong mode:\n"
504584" -P exchange packets between two stations\n"
505585" max_wait_s generate a new packet if no response is received (master)\n\n"
586" Round-trip time measurement:\n"
587" -R send/receive RTT measurement packets\n"
588" packets number of packets to send (master)\n"
589" size size of packets in bytes\n"
506590" constant wave test mode (transmit only):\n"
507591" -T offset test mode. offset is the frequency offset of the constant\n"
508592" wave in MHz: -2, -0.5, or +0.5\n"
...... 
519603" -p power transmit power, -17.2 to 3.0 dBm (default %.1f)\n"
520604" -r rate data rate, 250k, 500k, 1M, or 2M (default: 250k)\n"
521605" -t trim trim capacitor, 0 to 15 (default %d)\n"
522        , name, name, name, name, name,
606        , name, name, name, name, name, name,
523607        DEFAULT_CHANNEL, atrf_default_driver_name(),
524608        2405+5*(DEFAULT_CHANNEL-11), DEFAULT_POWER,
525609        DEFAULT_TRIM);
...... 
545629    int channel = DEFAULT_CHANNEL;
546630    double power = DEFAULT_POWER;
547631    uint8_t rate = OQPSK_DATA_RATE_250;
548    int trim = DEFAULT_TRIM, times = 1;
632    int trim = DEFAULT_TRIM, times = 1, bytes;
549633    uint8_t cont_tx = 0;
550634    double pause_s = 0;
551635    char *end;
...... 
555639    const char *pcap_file = NULL;
556640    struct atrf_dsc *dsc;
557641
558    while ((c = getopt(argc, argv, "c:C:d:E:f:Ho:p:Pr:t:T:")) != EOF)
642    while ((c = getopt(argc, argv, "c:C:d:E:f:Ho:p:Pr:Rt:T:")) != EOF)
559643        switch (c) {
560644        case 'c':
561645            channel = strtoul(optarg, &end, 0);
...... 
616700            else
617701                usage(*argv);
618702            break;
703        case 'R':
704            set_mode(&mode, mode_rtt);
705            break;
619706        case 't':
620707            trim = strtoul(optarg, &end, 0);
621708            if (*end)
...... 
660747            set_power_dBm(dsc, power, 1);
661748            ping(dsc, pause_s, 0);
662749            break;
750        case mode_rtt:
751            set_power_dBm(dsc, power, 1);
752            rtt_slave(dsc);
753            break;
663754        case mode_cont_tx:
664755            set_power_dBm(dsc, power, 0);
665756            status = test_mode(dsc, cont_tx, NULL);
...... 
678769            /* fall through */
679770        case mode_cont_tx:
680771            usage(*argv);
772        case mode_rtt:
773            times = strtoul(argv[optind], &end, 0);
774            if (*end)
775                usage(*argv);
776            bytes = strtoul(argv[optind+1], &end, 0);
777            if (*end)
778                usage(*argv);
779            dsc = init_txrx(driver, trim, clkm);
780            set_channel(dsc, channel);
781            set_rate(dsc, rate);
782            set_power_dBm(dsc, power, 1);
783            rtt_master(dsc, times, bytes);
784            goto done;
681785        default:
682786            abort();
683787        }
...... 
712816            set_power_dBm(dsc, power, 1);
713817            ping(dsc, pause_s, 1);
714818            break;
819        case mode_rtt:
820            usage(*argv);
821            break;
715822        case mode_cont_tx:
716823            set_power_dBm(dsc, power, 0);
717824            status = test_mode(dsc, cont_tx, argv[optind]);
...... 
724831    default:
725832        usage(*argv);
726833    }
834done:
727835
728836    atrf_close(dsc);
729837

Archive Download the corresponding diff file



interactive