2010-08-21 07:42:58 +03:00
|
|
|
/*
|
2010-11-11 15:24:22 +02:00
|
|
|
* atrf-txrx/atrf-txrx.c - ben-wpan AT86RF230 TX/RX
|
2010-08-21 07:42:58 +03:00
|
|
|
*
|
2013-02-12 15:47:12 +02:00
|
|
|
* Written 2010-2011, 2013 by Werner Almesberger
|
|
|
|
* Copyright 2010-2011, 2013 Werner Almesberger
|
2010-08-21 07:42:58 +03:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-09-09 23:42:47 +03:00
|
|
|
#include <stdint.h>
|
2010-08-21 07:42:58 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
Merged uSD driver into unified tool build, completed conversion of tools.
- atusd/tools/lib/atusd.c: moved to tools/lib/
- atusd/tools/lib/atusd.h: removed, we can now use tools/include/atspi.h
- tools/lib/atusd.c: added copyright header
- tools/lib/atusd.c: updated for driver API
- tools/lib/Makefile: added atusd.o
- tools/Makefile.common: moved common elements from all other makefiles in
tools/*/ here
- tools/Makefile.common: added target-specific compiler and flags
- tools/atspi-id/Makefile, tools/atspi-reset/Makefile,
tools/atspi-rssi/Makefile, tools/atspi-trim/Makefile,
tools/atspi-txrx/Makefile, tools/lib/Makefile: used Makefile.common
- tools/lib/Makefile: differentiate USB and uSD build
- tools/atspi-id/atspi-id.c, tools/atspi-reset/atspi-reset.c,
tools/atspi-rssi/atspi-rssi.c, tools/atspi-trim/atspi-trim.c,
tools/atspi-txr/atspi-txr.c: updated for driver-agnostic API
- tools/atspi-id/atspi-id.c, tools/atspi-reset/atspi-reset.c,
tools/atspi-rssi/atspi-rssi.c, tools/atspi-trim/atspi-trim.c,
tools/atspi-txr/atspi-txr.c: corrected AF86RF230 typo in title
- tools/include/atspi.h, tools/lib/atspi.c, tools/lib/driver.c,
tools/lib/atusb.c: brought back support for atspi_error and
atspi_clear_error
- tools/atspi-id/atspi-id.c (atspi_get_protocol): renamed to get_protocol,
to make it clear that it's not from libatspi
- tools/atspi-id/atspi-id.c (atspi_get_build): renamed to get_build, to
make it clear that it's not from libatspi
- tools/include/atspi.h, tools/lib/atspi.c (atspi_usb_handle): new function
to obtain a driver's USB device handle (or NULL if the driver doesn't use
USB)
2010-09-06 02:32:58 +03:00
|
|
|
#include <unistd.h>
|
2010-08-24 12:16:48 +03:00
|
|
|
#include <string.h>
|
2010-09-14 23:12:03 +03:00
|
|
|
#include <math.h>
|
|
|
|
#include <signal.h>
|
2010-11-12 02:31:15 +02:00
|
|
|
#include <sys/wait.h>
|
2011-01-19 08:22:24 +02:00
|
|
|
#include <sys/time.h>
|
2010-08-21 07:42:58 +03:00
|
|
|
|
|
|
|
#include "at86rf230.h"
|
The Great ATSPI Renaming, part 4: rename include/atspi.h to include/atrf.h
- include/atspi.h: renamed to include/atrf.h
- include/misctxrx.h, lib/atrf.c, lib/misctxrx.c, atspi-id/atspi-id.c,
atspi-reset/atspi-reset.c, atspi-rssi/atspi-rssi.c, atspi-rssi/gui.c,
atspi-rssi/gui.h, atspi-trim/atspi-trim.c, atspi-txrx/atspi-txrx.c:
change #include "atspi.h" to #include "atrf.h"
2010-11-11 13:58:47 +02:00
|
|
|
#include "atrf.h"
|
2010-09-09 23:42:47 +03:00
|
|
|
#include "misctxrx.h"
|
2011-04-10 16:24:24 +03:00
|
|
|
#include "cwtest.h"
|
2010-08-21 07:42:58 +03:00
|
|
|
|
2011-01-19 08:22:24 +02:00
|
|
|
#include "pcap.h"
|
|
|
|
|
2010-08-21 07:42:58 +03:00
|
|
|
|
2010-08-24 12:16:48 +03:00
|
|
|
/*
|
|
|
|
* According to IEEE 802.15.4-2003 section E.2.6, channel 15 is the only
|
|
|
|
* channel that falls into the 802.11 guard bands in North America an Europe.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define DEFAULT_CHANNEL 15 /* channel 15, 2425 MHz */
|
|
|
|
|
2011-03-04 04:18:43 +02:00
|
|
|
#define DEFAULT_TRIM 8 /* trim range is 0-15, see also ECN0002 */
|
|
|
|
|
|
|
|
|
2010-08-24 12:16:48 +03:00
|
|
|
/*
|
|
|
|
* Transmit power, dBm. IEEE 802.15.4-2003 section E.3.1.3 specifies a transmit
|
|
|
|
* power of 0 dBm for IEEE 802.15.4. We assume an antenna gain of 3 dB or
|
|
|
|
* better.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define DEFAULT_POWER -3.2 /* transmit power, dBm */
|
|
|
|
|
|
|
|
|
2011-01-20 20:23:56 +02:00
|
|
|
struct ping {
|
|
|
|
uint32_t seq; /* sequence number from originator, > 0 */
|
|
|
|
uint32_t ack; /* last sequence number received, 0 if none */
|
|
|
|
uint8_t pad[117]; /* pad to 127 bytes */
|
|
|
|
uint16_t crc;
|
|
|
|
} __attribute__((__packed__));
|
|
|
|
|
|
|
|
enum rx_res {
|
|
|
|
rx_exit,
|
|
|
|
rx_good,
|
|
|
|
rx_bad,
|
|
|
|
rx_timeout,
|
|
|
|
};
|
|
|
|
|
2013-02-12 15:47:12 +02:00
|
|
|
enum mode {
|
|
|
|
mode_msg,
|
|
|
|
mode_hmac,
|
|
|
|
mode_per,
|
|
|
|
mode_ping,
|
|
|
|
mode_cont_tx,
|
|
|
|
};
|
|
|
|
|
2011-01-20 20:23:56 +02:00
|
|
|
|
2010-09-14 23:12:03 +03:00
|
|
|
static volatile int run = 1;
|
|
|
|
|
|
|
|
|
2011-01-13 00:13:21 +02:00
|
|
|
/*
|
|
|
|
* clkm: 0 disable CLKM
|
|
|
|
* >0 output 2^(clkm-1) MHz signal
|
|
|
|
*/
|
|
|
|
|
tools/: added option -d driver[:arg] to all tools
- atrf-id/atrf-id.c (main), atrf-reset/atrf-reset.c (main),
atrf-trim/atrf-trim.c (main): changed command-line parsing to use
"getopt"
- atrf-id/atrf-id.c (usage, main), atrf-reset/atrf-reset.c (usage, main),
atrf-rssi/atrf-rssi.c (usage, main), atrf-trim/atrf-trim.c (usage,
main), atrf-txrx/atrf-txrx.c (init_txrx, usage, main),
atrf-xtal/atrf-xtal.c (usage, main): added option -d to select a driver
2011-04-10 13:13:53 +03:00
|
|
|
static struct atrf_dsc *init_txrx(const char *driver, int trim, unsigned mhz)
|
2010-08-24 12:16:48 +03:00
|
|
|
{
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
struct atrf_dsc *dsc;
|
2010-08-24 12:16:48 +03:00
|
|
|
|
tools/: added option -d driver[:arg] to all tools
- atrf-id/atrf-id.c (main), atrf-reset/atrf-reset.c (main),
atrf-trim/atrf-trim.c (main): changed command-line parsing to use
"getopt"
- atrf-id/atrf-id.c (usage, main), atrf-reset/atrf-reset.c (usage, main),
atrf-rssi/atrf-rssi.c (usage, main), atrf-trim/atrf-trim.c (usage,
main), atrf-txrx/atrf-txrx.c (init_txrx, usage, main),
atrf-xtal/atrf-xtal.c (usage, main): added option -d to select a driver
2011-04-10 13:13:53 +03:00
|
|
|
dsc = atrf_open(driver);
|
Merged uSD driver into unified tool build, completed conversion of tools.
- atusd/tools/lib/atusd.c: moved to tools/lib/
- atusd/tools/lib/atusd.h: removed, we can now use tools/include/atspi.h
- tools/lib/atusd.c: added copyright header
- tools/lib/atusd.c: updated for driver API
- tools/lib/Makefile: added atusd.o
- tools/Makefile.common: moved common elements from all other makefiles in
tools/*/ here
- tools/Makefile.common: added target-specific compiler and flags
- tools/atspi-id/Makefile, tools/atspi-reset/Makefile,
tools/atspi-rssi/Makefile, tools/atspi-trim/Makefile,
tools/atspi-txrx/Makefile, tools/lib/Makefile: used Makefile.common
- tools/lib/Makefile: differentiate USB and uSD build
- tools/atspi-id/atspi-id.c, tools/atspi-reset/atspi-reset.c,
tools/atspi-rssi/atspi-rssi.c, tools/atspi-trim/atspi-trim.c,
tools/atspi-txr/atspi-txr.c: updated for driver-agnostic API
- tools/atspi-id/atspi-id.c, tools/atspi-reset/atspi-reset.c,
tools/atspi-rssi/atspi-rssi.c, tools/atspi-trim/atspi-trim.c,
tools/atspi-txr/atspi-txr.c: corrected AF86RF230 typo in title
- tools/include/atspi.h, tools/lib/atspi.c, tools/lib/driver.c,
tools/lib/atusb.c: brought back support for atspi_error and
atspi_clear_error
- tools/atspi-id/atspi-id.c (atspi_get_protocol): renamed to get_protocol,
to make it clear that it's not from libatspi
- tools/atspi-id/atspi-id.c (atspi_get_build): renamed to get_build, to
make it clear that it's not from libatspi
- tools/include/atspi.h, tools/lib/atspi.c (atspi_usb_handle): new function
to obtain a driver's USB device handle (or NULL if the driver doesn't use
USB)
2010-09-06 02:32:58 +03:00
|
|
|
if (!dsc)
|
2010-08-24 12:16:48 +03:00
|
|
|
exit(1);
|
|
|
|
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
atrf_reset_rf(dsc);
|
|
|
|
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TRX_OFF);
|
2011-01-13 00:13:21 +02:00
|
|
|
|
2011-01-16 21:03:11 +02:00
|
|
|
#if 1 // def HAVE_USB /* @@@ yeah, ugly */
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
atrf_reg_write(dsc, REG_XOSC_CTRL,
|
2010-08-24 12:16:48 +03:00
|
|
|
(XTAL_MODE_INT << XTAL_MODE_SHIFT) | trim);
|
Updated atusd driver for new hardware. Make use of the interrupt line.
- tools/lib/atusd.c (spi_send_partial, spi_send): removed the old spi_send
and renamed spi_send_partial to spi_send
- tools/lib/atusd.c (atusd_cycle, spi_send, spi_recv, atusd_open): updated
for removal of SLP_TR and split of MxSx into MOSI and MISO
- tools/lib/atusd.c (atusd_reset_rf, atusd_open): added delays to precharge
the capacitors
- tools/lib/atusd.c (atusd_reset, spi_data_in, spi_data_out, spi_finish):
removed functions for obsolete hardware features
- tools/lib/atusd.c (atusd_reg_read): removed calls to removed functions
- tools/lib/atusd.c (atusd_buf_write, atusd_buf_read, atusd_driver): new
buffer read/write functions
- tools/atspi-txrx/atspi-txrx.c (init_txrx): set the internal osciallator
trim only in the USB version. Switch to the external oscillator in the
uSD version.
- tools/atspi-rssi/atspi-rssi.c (sweep), tools/atspi-txrx/atspi-txrx.c
(set_channel): wait for the PLL to settle after setting the channel
- tools/include/atspi.h, tools/lib/atspi.c (atspi_interrupt),
tools/lib/driver.h (struct atspi_driver), tools/lib/atusd.c
(atusd_interrupt): new function to poll the interrupt line
- tools/atspi-txrx/atspi-txrx.c (receive): only read REG_IRQ_STATUS if
there is a pending interrupt
- tools/atspi-id/atspi-id.c (usage): print "usage:" as well
- tools/Makefile (upload): upload the atspi tools to the Ben
2010-09-09 15:19:06 +03:00
|
|
|
#else
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
atrf_reg_write(dsc, REG_XOSC_CTRL, XTAL_MODE_EXT << XTAL_MODE_SHIFT);
|
Updated atusd driver for new hardware. Make use of the interrupt line.
- tools/lib/atusd.c (spi_send_partial, spi_send): removed the old spi_send
and renamed spi_send_partial to spi_send
- tools/lib/atusd.c (atusd_cycle, spi_send, spi_recv, atusd_open): updated
for removal of SLP_TR and split of MxSx into MOSI and MISO
- tools/lib/atusd.c (atusd_reset_rf, atusd_open): added delays to precharge
the capacitors
- tools/lib/atusd.c (atusd_reset, spi_data_in, spi_data_out, spi_finish):
removed functions for obsolete hardware features
- tools/lib/atusd.c (atusd_reg_read): removed calls to removed functions
- tools/lib/atusd.c (atusd_buf_write, atusd_buf_read, atusd_driver): new
buffer read/write functions
- tools/atspi-txrx/atspi-txrx.c (init_txrx): set the internal osciallator
trim only in the USB version. Switch to the external oscillator in the
uSD version.
- tools/atspi-rssi/atspi-rssi.c (sweep), tools/atspi-txrx/atspi-txrx.c
(set_channel): wait for the PLL to settle after setting the channel
- tools/include/atspi.h, tools/lib/atspi.c (atspi_interrupt),
tools/lib/driver.h (struct atspi_driver), tools/lib/atusd.c
(atusd_interrupt): new function to poll the interrupt line
- tools/atspi-txrx/atspi-txrx.c (receive): only read REG_IRQ_STATUS if
there is a pending interrupt
- tools/atspi-id/atspi-id.c (usage): print "usage:" as well
- tools/Makefile (upload): upload the atspi tools to the Ben
2010-09-09 15:19:06 +03:00
|
|
|
#endif
|
2011-01-13 00:13:21 +02:00
|
|
|
|
2011-02-11 04:11:34 +02:00
|
|
|
if (!atrf_set_clkm(dsc, mhz))
|
|
|
|
if (mhz) {
|
|
|
|
atrf_close(dsc);
|
|
|
|
exit(1);
|
|
|
|
}
|
2010-08-24 12:16:48 +03:00
|
|
|
|
2011-01-10 00:32:05 +02:00
|
|
|
/* We want to see all interrupts, not only the ones we're expecting. */
|
|
|
|
atrf_reg_write(dsc, REG_IRQ_MASK, 0xff);
|
|
|
|
|
2011-06-20 23:27:19 +03:00
|
|
|
flush_interrupts(dsc);
|
2011-01-10 00:32:05 +02:00
|
|
|
if (atrf_identify(dsc) == artf_at86rf231)
|
tools/: major overhaul of wait_for_interrupt; uses atrf_interrupt_wait now
- include/misctxrx.h (wait_for_interrupt), lib/misctxrx.c
(wait_for_interrupt): replaced sleep_us*timeout limiting mechanism
with a single timeout value in milliseconds
- lib/misctxrx.c (wait_for_interrupt): use atrf_interrupt_wait instead
of polling
- lib/misctxrx.c (wait_for_interrupt): cleaned up control flow
- lib/misctxrx.c (run, die, wait_for_interrupt): renamed variable "run"
to more specific "sigint"
- atrf-txrx/atrf-txrx.c (ping_rx, ping): pass timeout in milliseconds,
not deciseconds
- atrf-rssi/atrf-rssi.c (sweep), atrf-rssi/gui.c (sweep),
atrf-txrx/atrf-txrx.c (init_txrx, receive_message, receive_pcap,
receive, transmit, transmit_pattern, ping_tx, ping_rx),
atrf-xmit/atrf-xmit.c (init_tx, init_rx, xfer_one),
lib/cwtest.c (enter_test_mode_230, start_test_mode_231):
updated use of wait_for_interrupt
2011-06-21 01:58:31 +03:00
|
|
|
wait_for_interrupt(dsc, IRQ_CCA_ED_DONE, IRQ_CCA_ED_DONE, 1);
|
|
|
|
/* according to table 7-1, 37 us max */
|
2010-09-09 23:23:47 +03:00
|
|
|
|
Merged uSD driver into unified tool build, completed conversion of tools.
- atusd/tools/lib/atusd.c: moved to tools/lib/
- atusd/tools/lib/atusd.h: removed, we can now use tools/include/atspi.h
- tools/lib/atusd.c: added copyright header
- tools/lib/atusd.c: updated for driver API
- tools/lib/Makefile: added atusd.o
- tools/Makefile.common: moved common elements from all other makefiles in
tools/*/ here
- tools/Makefile.common: added target-specific compiler and flags
- tools/atspi-id/Makefile, tools/atspi-reset/Makefile,
tools/atspi-rssi/Makefile, tools/atspi-trim/Makefile,
tools/atspi-txrx/Makefile, tools/lib/Makefile: used Makefile.common
- tools/lib/Makefile: differentiate USB and uSD build
- tools/atspi-id/atspi-id.c, tools/atspi-reset/atspi-reset.c,
tools/atspi-rssi/atspi-rssi.c, tools/atspi-trim/atspi-trim.c,
tools/atspi-txr/atspi-txr.c: updated for driver-agnostic API
- tools/atspi-id/atspi-id.c, tools/atspi-reset/atspi-reset.c,
tools/atspi-rssi/atspi-rssi.c, tools/atspi-trim/atspi-trim.c,
tools/atspi-txr/atspi-txr.c: corrected AF86RF230 typo in title
- tools/include/atspi.h, tools/lib/atspi.c, tools/lib/driver.c,
tools/lib/atusb.c: brought back support for atspi_error and
atspi_clear_error
- tools/atspi-id/atspi-id.c (atspi_get_protocol): renamed to get_protocol,
to make it clear that it's not from libatspi
- tools/atspi-id/atspi-id.c (atspi_get_build): renamed to get_build, to
make it clear that it's not from libatspi
- tools/include/atspi.h, tools/lib/atspi.c (atspi_usb_handle): new function
to obtain a driver's USB device handle (or NULL if the driver doesn't use
USB)
2010-09-06 02:32:58 +03:00
|
|
|
return dsc;
|
2010-08-24 12:16:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
static void set_channel(struct atrf_dsc *dsc, int channel)
|
2010-08-24 12:16:48 +03:00
|
|
|
{
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
atrf_reg_write(dsc, REG_PHY_CC_CCA, (1 << CCA_MODE_SHIFT) | channel);
|
2010-08-24 12:16:48 +03:00
|
|
|
}
|
2010-08-21 07:42:58 +03:00
|
|
|
|
2010-08-24 12:16:48 +03:00
|
|
|
|
2011-01-21 00:32:40 +02:00
|
|
|
static void set_rate(struct atrf_dsc *dsc, uint8_t rate)
|
|
|
|
{
|
|
|
|
if (!rate)
|
|
|
|
return;
|
|
|
|
switch (atrf_identify(dsc)) {
|
|
|
|
case artf_at86rf230:
|
|
|
|
fprintf(stderr, "AT86RF230 only supports 250 kbps\n");
|
|
|
|
break;
|
|
|
|
case artf_at86rf231:
|
|
|
|
atrf_reg_write(dsc, REG_TRX_CTRL_2, rate);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-19 08:22:24 +02:00
|
|
|
static void receive_message(struct atrf_dsc *dsc)
|
2010-08-24 12:16:48 +03:00
|
|
|
{
|
2010-08-25 03:03:39 +03:00
|
|
|
uint8_t buf[MAX_PSDU+1]; /* PSDU+LQI */
|
2010-08-24 12:16:48 +03:00
|
|
|
int n, ok, i;
|
2010-09-09 23:23:47 +03:00
|
|
|
uint8_t ed, lqi;
|
2010-08-24 12:16:48 +03:00
|
|
|
|
|
|
|
fprintf(stderr, "Ready.\n");
|
2011-04-19 12:59:19 +03:00
|
|
|
wait_for_interrupt(dsc, IRQ_TRX_END,
|
tools/: major overhaul of wait_for_interrupt; uses atrf_interrupt_wait now
- include/misctxrx.h (wait_for_interrupt), lib/misctxrx.c
(wait_for_interrupt): replaced sleep_us*timeout limiting mechanism
with a single timeout value in milliseconds
- lib/misctxrx.c (wait_for_interrupt): use atrf_interrupt_wait instead
of polling
- lib/misctxrx.c (wait_for_interrupt): cleaned up control flow
- lib/misctxrx.c (run, die, wait_for_interrupt): renamed variable "run"
to more specific "sigint"
- atrf-txrx/atrf-txrx.c (ping_rx, ping): pass timeout in milliseconds,
not deciseconds
- atrf-rssi/atrf-rssi.c (sweep), atrf-rssi/gui.c (sweep),
atrf-txrx/atrf-txrx.c (init_txrx, receive_message, receive_pcap,
receive, transmit, transmit_pattern, ping_tx, ping_rx),
atrf-xmit/atrf-xmit.c (init_tx, init_rx, xfer_one),
lib/cwtest.c (enter_test_mode_230, start_test_mode_231):
updated use of wait_for_interrupt
2011-06-21 01:58:31 +03:00
|
|
|
IRQ_TRX_END | IRQ_RX_START | IRQ_AMI, 0);
|
2010-09-14 23:12:03 +03:00
|
|
|
if (!run)
|
|
|
|
return;
|
2010-08-24 12:16:48 +03:00
|
|
|
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
n = atrf_buf_read(dsc, buf, sizeof(buf));
|
2010-08-24 12:16:48 +03:00
|
|
|
if (n < 0)
|
|
|
|
exit(1);
|
|
|
|
if (n < 3) {
|
|
|
|
fprintf(stderr, "%d bytes received\n", n);
|
|
|
|
exit(1);
|
|
|
|
}
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
ed = atrf_reg_read(dsc, REG_PHY_ED_LEVEL);
|
|
|
|
ok = !!(atrf_reg_read(dsc, REG_PHY_RSSI) & RX_CRC_VALID);
|
2010-09-09 23:23:47 +03:00
|
|
|
lqi = buf[n-1];
|
|
|
|
fprintf(stderr, "%d bytes payload, CRC %s, LQI %u, ED %d dBm\n",
|
|
|
|
n-3, ok ? "OK" : "BAD", lqi, -91+ed);
|
2010-08-24 12:16:48 +03:00
|
|
|
for (i = 0; i != n-3; i++)
|
|
|
|
putchar(buf[i] < ' ' || buf[i] > '~' ? '?' : buf[i]);
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-19 08:22:24 +02:00
|
|
|
static void write_pcap_hdr(FILE *file)
|
|
|
|
{
|
|
|
|
struct pcap_file_header hdr = {
|
2011-01-19 18:16:03 +02:00
|
|
|
.magic = PCAP_FILE_MAGIC,
|
2011-01-19 08:22:24 +02:00
|
|
|
.version_major = 2,
|
|
|
|
.version_minor = 4,
|
|
|
|
.thiszone = 0,
|
|
|
|
.sigfigs = 0,
|
|
|
|
.snaplen = MAX_PSDU,
|
|
|
|
.linktype = DLT_IEEE802_15_4
|
|
|
|
};
|
|
|
|
|
|
|
|
if (fwrite(&hdr, sizeof(hdr), 1, file) != 1) {
|
|
|
|
perror("fwrite");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void write_pcap_rec(FILE *file, const struct timeval *tv,
|
|
|
|
const void *buf, int n)
|
|
|
|
{
|
|
|
|
struct pcap_pkthdr hdr = {
|
|
|
|
.ts_sec = tv->tv_sec,
|
|
|
|
.ts_usec = tv->tv_usec,
|
|
|
|
.caplen = n,
|
|
|
|
.len = n
|
|
|
|
};
|
|
|
|
|
|
|
|
if (fwrite(&hdr, sizeof(hdr), 1, file) != 1) {
|
|
|
|
perror("fwrite");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (fwrite(buf, n, 1, file) != 1) {
|
|
|
|
perror("fwrite");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void receive_pcap(struct atrf_dsc *dsc, const char *name)
|
|
|
|
{
|
|
|
|
FILE *file;
|
|
|
|
uint8_t buf[MAX_PSDU+1]; /* PSDU+LQI */
|
|
|
|
struct timeval now;
|
|
|
|
int n;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
file = fopen(name, "w");
|
|
|
|
if (!file) {
|
|
|
|
perror(name);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
write_pcap_hdr(file);
|
|
|
|
while (run) {
|
|
|
|
wait_for_interrupt(dsc,
|
tools/: major overhaul of wait_for_interrupt; uses atrf_interrupt_wait now
- include/misctxrx.h (wait_for_interrupt), lib/misctxrx.c
(wait_for_interrupt): replaced sleep_us*timeout limiting mechanism
with a single timeout value in milliseconds
- lib/misctxrx.c (wait_for_interrupt): use atrf_interrupt_wait instead
of polling
- lib/misctxrx.c (wait_for_interrupt): cleaned up control flow
- lib/misctxrx.c (run, die, wait_for_interrupt): renamed variable "run"
to more specific "sigint"
- atrf-txrx/atrf-txrx.c (ping_rx, ping): pass timeout in milliseconds,
not deciseconds
- atrf-rssi/atrf-rssi.c (sweep), atrf-rssi/gui.c (sweep),
atrf-txrx/atrf-txrx.c (init_txrx, receive_message, receive_pcap,
receive, transmit, transmit_pattern, ping_tx, ping_rx),
atrf-xmit/atrf-xmit.c (init_tx, init_rx, xfer_one),
lib/cwtest.c (enter_test_mode_230, start_test_mode_231):
updated use of wait_for_interrupt
2011-06-21 01:58:31 +03:00
|
|
|
IRQ_TRX_END, IRQ_TRX_END | IRQ_RX_START | IRQ_AMI, 0);
|
2011-01-19 08:22:24 +02:00
|
|
|
if (!run)
|
|
|
|
break;
|
|
|
|
gettimeofday(&now, NULL);
|
|
|
|
n = atrf_buf_read(dsc, buf, sizeof(buf));
|
|
|
|
if (n < 0)
|
|
|
|
exit(1);
|
|
|
|
if (n < 2) {
|
|
|
|
fprintf(stderr, "%d bytes received\n", n);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
write_pcap_rec(file, &now, buf, n-1);
|
|
|
|
(void) write(2, ".", 1);
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
if (fclose(file) == EOF) {
|
|
|
|
perror(name);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
fprintf(stderr, "%sreceived %d message%s\n", count ? "\n" : "",
|
|
|
|
count, count == 1 ? "" : "s");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void receive(struct atrf_dsc *dsc, const char *name)
|
|
|
|
{
|
|
|
|
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_RX_ON);
|
|
|
|
/*
|
|
|
|
* 180 us, according to AVR2001 section 4.2. We time out after
|
|
|
|
* nominally 200 us.
|
|
|
|
*/
|
tools/: major overhaul of wait_for_interrupt; uses atrf_interrupt_wait now
- include/misctxrx.h (wait_for_interrupt), lib/misctxrx.c
(wait_for_interrupt): replaced sleep_us*timeout limiting mechanism
with a single timeout value in milliseconds
- lib/misctxrx.c (wait_for_interrupt): use atrf_interrupt_wait instead
of polling
- lib/misctxrx.c (wait_for_interrupt): cleaned up control flow
- lib/misctxrx.c (run, die, wait_for_interrupt): renamed variable "run"
to more specific "sigint"
- atrf-txrx/atrf-txrx.c (ping_rx, ping): pass timeout in milliseconds,
not deciseconds
- atrf-rssi/atrf-rssi.c (sweep), atrf-rssi/gui.c (sweep),
atrf-txrx/atrf-txrx.c (init_txrx, receive_message, receive_pcap,
receive, transmit, transmit_pattern, ping_tx, ping_rx),
atrf-xmit/atrf-xmit.c (init_tx, init_rx, xfer_one),
lib/cwtest.c (enter_test_mode_230, start_test_mode_231):
updated use of wait_for_interrupt
2011-06-21 01:58:31 +03:00
|
|
|
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 1);
|
2011-01-19 08:22:24 +02:00
|
|
|
|
|
|
|
if (name)
|
|
|
|
receive_pcap(dsc, name);
|
|
|
|
else
|
|
|
|
receive_message(dsc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
static void transmit(struct atrf_dsc *dsc, const char *msg, int times)
|
2010-08-24 12:16:48 +03:00
|
|
|
{
|
|
|
|
uint8_t buf[MAX_PSDU];
|
|
|
|
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_PLL_ON);
|
2010-09-09 23:23:47 +03:00
|
|
|
/*
|
|
|
|
* 180 us, according to AVR2001 section 4.3. We time out after
|
|
|
|
* nominally 200 us.
|
|
|
|
*/
|
tools/: major overhaul of wait_for_interrupt; uses atrf_interrupt_wait now
- include/misctxrx.h (wait_for_interrupt), lib/misctxrx.c
(wait_for_interrupt): replaced sleep_us*timeout limiting mechanism
with a single timeout value in milliseconds
- lib/misctxrx.c (wait_for_interrupt): use atrf_interrupt_wait instead
of polling
- lib/misctxrx.c (wait_for_interrupt): cleaned up control flow
- lib/misctxrx.c (run, die, wait_for_interrupt): renamed variable "run"
to more specific "sigint"
- atrf-txrx/atrf-txrx.c (ping_rx, ping): pass timeout in milliseconds,
not deciseconds
- atrf-rssi/atrf-rssi.c (sweep), atrf-rssi/gui.c (sweep),
atrf-txrx/atrf-txrx.c (init_txrx, receive_message, receive_pcap,
receive, transmit, transmit_pattern, ping_tx, ping_rx),
atrf-xmit/atrf-xmit.c (init_tx, init_rx, xfer_one),
lib/cwtest.c (enter_test_mode_230, start_test_mode_231):
updated use of wait_for_interrupt
2011-06-21 01:58:31 +03:00
|
|
|
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 1);
|
2010-08-24 12:16:48 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We need to copy the message to append the CRC placeholders.
|
|
|
|
*/
|
|
|
|
strcpy((void *) buf, msg);
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
atrf_buf_write(dsc, buf, strlen(msg)+2);
|
2010-08-24 12:16:48 +03:00
|
|
|
|
2010-09-14 23:12:03 +03:00
|
|
|
while (run && times--) {
|
|
|
|
/* @@@ should wait for clear channel */
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TX_START);
|
2010-09-09 23:23:47 +03:00
|
|
|
|
2010-09-14 23:12:03 +03:00
|
|
|
/* wait up to 10 ms (nominally) */
|
|
|
|
wait_for_interrupt(dsc, IRQ_TRX_END,
|
tools/: major overhaul of wait_for_interrupt; uses atrf_interrupt_wait now
- include/misctxrx.h (wait_for_interrupt), lib/misctxrx.c
(wait_for_interrupt): replaced sleep_us*timeout limiting mechanism
with a single timeout value in milliseconds
- lib/misctxrx.c (wait_for_interrupt): use atrf_interrupt_wait instead
of polling
- lib/misctxrx.c (wait_for_interrupt): cleaned up control flow
- lib/misctxrx.c (run, die, wait_for_interrupt): renamed variable "run"
to more specific "sigint"
- atrf-txrx/atrf-txrx.c (ping_rx, ping): pass timeout in milliseconds,
not deciseconds
- atrf-rssi/atrf-rssi.c (sweep), atrf-rssi/gui.c (sweep),
atrf-txrx/atrf-txrx.c (init_txrx, receive_message, receive_pcap,
receive, transmit, transmit_pattern, ping_tx, ping_rx),
atrf-xmit/atrf-xmit.c (init_tx, init_rx, xfer_one),
lib/cwtest.c (enter_test_mode_230, start_test_mode_231):
updated use of wait_for_interrupt
2011-06-21 01:58:31 +03:00
|
|
|
IRQ_TRX_END | IRQ_PLL_LOCK, 10);
|
2010-09-14 23:12:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-12 19:32:18 +03:00
|
|
|
static void receive_hmac(struct atrf_dsc *dsc)
|
|
|
|
{
|
|
|
|
uint8_t buf[MAX_PSDU];
|
|
|
|
uint8_t lqi;
|
|
|
|
int n, i;
|
|
|
|
|
|
|
|
atrf_rx_mode(dsc, 1);
|
|
|
|
n = atrf_rx(dsc, buf, sizeof(buf), &lqi);
|
|
|
|
atrf_rx_mode(dsc, 0);
|
|
|
|
|
|
|
|
if (n < 2) {
|
|
|
|
fprintf(stderr, "%d bytes received\n", n);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
for (i = 0; i != n-2; i++)
|
|
|
|
putchar(buf[i] < ' ' || buf[i] > '~' ? '?' : buf[i]);
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void transmit_hmac(struct atrf_dsc *dsc, const char *msg)
|
|
|
|
{
|
|
|
|
atrf_rx_mode(dsc, 1);
|
|
|
|
atrf_tx(dsc, msg, strlen(msg));
|
|
|
|
atrf_rx_mode(dsc, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-19 17:24:20 +02:00
|
|
|
static void transmit_pattern(struct atrf_dsc *dsc, double pause_s, int times)
|
|
|
|
{
|
|
|
|
uint8_t buf[MAX_PSDU];
|
|
|
|
uint8_t n = 0;
|
|
|
|
int us = fmod(pause_s, 1)*1000000;
|
|
|
|
|
|
|
|
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_PLL_ON);
|
|
|
|
/*
|
|
|
|
* 180 us, according to AVR2001 section 4.3. We time out after
|
|
|
|
* nominally 200 us.
|
|
|
|
*/
|
tools/: major overhaul of wait_for_interrupt; uses atrf_interrupt_wait now
- include/misctxrx.h (wait_for_interrupt), lib/misctxrx.c
(wait_for_interrupt): replaced sleep_us*timeout limiting mechanism
with a single timeout value in milliseconds
- lib/misctxrx.c (wait_for_interrupt): use atrf_interrupt_wait instead
of polling
- lib/misctxrx.c (wait_for_interrupt): cleaned up control flow
- lib/misctxrx.c (run, die, wait_for_interrupt): renamed variable "run"
to more specific "sigint"
- atrf-txrx/atrf-txrx.c (ping_rx, ping): pass timeout in milliseconds,
not deciseconds
- atrf-rssi/atrf-rssi.c (sweep), atrf-rssi/gui.c (sweep),
atrf-txrx/atrf-txrx.c (init_txrx, receive_message, receive_pcap,
receive, transmit, transmit_pattern, ping_tx, ping_rx),
atrf-xmit/atrf-xmit.c (init_tx, init_rx, xfer_one),
lib/cwtest.c (enter_test_mode_230, start_test_mode_231):
updated use of wait_for_interrupt
2011-06-21 01:58:31 +03:00
|
|
|
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 1);
|
2011-01-19 17:24:20 +02:00
|
|
|
|
|
|
|
while (run) {
|
|
|
|
memset(buf, n, sizeof(buf));
|
|
|
|
atrf_buf_write(dsc, buf, sizeof(buf));
|
|
|
|
|
|
|
|
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TX_START);
|
|
|
|
|
|
|
|
/* wait up to 10 ms (nominally) */
|
|
|
|
wait_for_interrupt(dsc, IRQ_TRX_END,
|
tools/: major overhaul of wait_for_interrupt; uses atrf_interrupt_wait now
- include/misctxrx.h (wait_for_interrupt), lib/misctxrx.c
(wait_for_interrupt): replaced sleep_us*timeout limiting mechanism
with a single timeout value in milliseconds
- lib/misctxrx.c (wait_for_interrupt): use atrf_interrupt_wait instead
of polling
- lib/misctxrx.c (wait_for_interrupt): cleaned up control flow
- lib/misctxrx.c (run, die, wait_for_interrupt): renamed variable "run"
to more specific "sigint"
- atrf-txrx/atrf-txrx.c (ping_rx, ping): pass timeout in milliseconds,
not deciseconds
- atrf-rssi/atrf-rssi.c (sweep), atrf-rssi/gui.c (sweep),
atrf-txrx/atrf-txrx.c (init_txrx, receive_message, receive_pcap,
receive, transmit, transmit_pattern, ping_tx, ping_rx),
atrf-xmit/atrf-xmit.c (init_tx, init_rx, xfer_one),
lib/cwtest.c (enter_test_mode_230, start_test_mode_231):
updated use of wait_for_interrupt
2011-06-21 01:58:31 +03:00
|
|
|
IRQ_TRX_END | IRQ_PLL_LOCK, 10);
|
2011-01-19 17:24:20 +02:00
|
|
|
|
|
|
|
if (pause_s >= 1)
|
|
|
|
sleep(pause_s);
|
|
|
|
if (us)
|
|
|
|
usleep(us);
|
|
|
|
|
|
|
|
if (times && !--times)
|
|
|
|
break;
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-07 19:59:23 +02:00
|
|
|
|
2011-01-20 20:23:56 +02:00
|
|
|
static void ping_tx(struct atrf_dsc *dsc, const struct ping *pck)
|
|
|
|
{
|
|
|
|
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_PLL_ON);
|
|
|
|
/*
|
|
|
|
* 180 us, according to AVR2001 section 4.3. We time out after
|
|
|
|
* nominally 200 us.
|
|
|
|
*/
|
tools/: major overhaul of wait_for_interrupt; uses atrf_interrupt_wait now
- include/misctxrx.h (wait_for_interrupt), lib/misctxrx.c
(wait_for_interrupt): replaced sleep_us*timeout limiting mechanism
with a single timeout value in milliseconds
- lib/misctxrx.c (wait_for_interrupt): use atrf_interrupt_wait instead
of polling
- lib/misctxrx.c (wait_for_interrupt): cleaned up control flow
- lib/misctxrx.c (run, die, wait_for_interrupt): renamed variable "run"
to more specific "sigint"
- atrf-txrx/atrf-txrx.c (ping_rx, ping): pass timeout in milliseconds,
not deciseconds
- atrf-rssi/atrf-rssi.c (sweep), atrf-rssi/gui.c (sweep),
atrf-txrx/atrf-txrx.c (init_txrx, receive_message, receive_pcap,
receive, transmit, transmit_pattern, ping_tx, ping_rx),
atrf-xmit/atrf-xmit.c (init_tx, init_rx, xfer_one),
lib/cwtest.c (enter_test_mode_230, start_test_mode_231):
updated use of wait_for_interrupt
2011-06-21 01:58:31 +03:00
|
|
|
wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 1);
|
2011-01-20 20:23:56 +02:00
|
|
|
|
|
|
|
atrf_buf_write(dsc, pck, sizeof(*pck));
|
|
|
|
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TX_START);
|
|
|
|
|
|
|
|
/* wait up to 10 ms (nominally) */
|
|
|
|
wait_for_interrupt(dsc, IRQ_TRX_END,
|
tools/: major overhaul of wait_for_interrupt; uses atrf_interrupt_wait now
- include/misctxrx.h (wait_for_interrupt), lib/misctxrx.c
(wait_for_interrupt): replaced sleep_us*timeout limiting mechanism
with a single timeout value in milliseconds
- lib/misctxrx.c (wait_for_interrupt): use atrf_interrupt_wait instead
of polling
- lib/misctxrx.c (wait_for_interrupt): cleaned up control flow
- lib/misctxrx.c (run, die, wait_for_interrupt): renamed variable "run"
to more specific "sigint"
- atrf-txrx/atrf-txrx.c (ping_rx, ping): pass timeout in milliseconds,
not deciseconds
- atrf-rssi/atrf-rssi.c (sweep), atrf-rssi/gui.c (sweep),
atrf-txrx/atrf-txrx.c (init_txrx, receive_message, receive_pcap,
receive, transmit, transmit_pattern, ping_tx, ping_rx),
atrf-xmit/atrf-xmit.c (init_tx, init_rx, xfer_one),
lib/cwtest.c (enter_test_mode_230, start_test_mode_231):
updated use of wait_for_interrupt
2011-06-21 01:58:31 +03:00
|
|
|
IRQ_TRX_END | IRQ_PLL_LOCK, 10);
|
2011-01-20 20:23:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
tools/: major overhaul of wait_for_interrupt; uses atrf_interrupt_wait now
- include/misctxrx.h (wait_for_interrupt), lib/misctxrx.c
(wait_for_interrupt): replaced sleep_us*timeout limiting mechanism
with a single timeout value in milliseconds
- lib/misctxrx.c (wait_for_interrupt): use atrf_interrupt_wait instead
of polling
- lib/misctxrx.c (wait_for_interrupt): cleaned up control flow
- lib/misctxrx.c (run, die, wait_for_interrupt): renamed variable "run"
to more specific "sigint"
- atrf-txrx/atrf-txrx.c (ping_rx, ping): pass timeout in milliseconds,
not deciseconds
- atrf-rssi/atrf-rssi.c (sweep), atrf-rssi/gui.c (sweep),
atrf-txrx/atrf-txrx.c (init_txrx, receive_message, receive_pcap,
receive, transmit, transmit_pattern, ping_tx, ping_rx),
atrf-xmit/atrf-xmit.c (init_tx, init_rx, xfer_one),
lib/cwtest.c (enter_test_mode_230, start_test_mode_231):
updated use of wait_for_interrupt
2011-06-21 01:58:31 +03:00
|
|
|
static enum rx_res ping_rx(struct atrf_dsc *dsc, struct ping *pck, int wait_ms)
|
2011-01-20 20:23:56 +02:00
|
|
|
{
|
|
|
|
uint8_t irq;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
atrf_reg_write(dsc, REG_TRX_STATE, TRX_CMD_RX_ON);
|
|
|
|
irq = wait_for_interrupt(dsc, IRQ_TRX_END,
|
tools/: major overhaul of wait_for_interrupt; uses atrf_interrupt_wait now
- include/misctxrx.h (wait_for_interrupt), lib/misctxrx.c
(wait_for_interrupt): replaced sleep_us*timeout limiting mechanism
with a single timeout value in milliseconds
- lib/misctxrx.c (wait_for_interrupt): use atrf_interrupt_wait instead
of polling
- lib/misctxrx.c (wait_for_interrupt): cleaned up control flow
- lib/misctxrx.c (run, die, wait_for_interrupt): renamed variable "run"
to more specific "sigint"
- atrf-txrx/atrf-txrx.c (ping_rx, ping): pass timeout in milliseconds,
not deciseconds
- atrf-rssi/atrf-rssi.c (sweep), atrf-rssi/gui.c (sweep),
atrf-txrx/atrf-txrx.c (init_txrx, receive_message, receive_pcap,
receive, transmit, transmit_pattern, ping_tx, ping_rx),
atrf-xmit/atrf-xmit.c (init_tx, init_rx, xfer_one),
lib/cwtest.c (enter_test_mode_230, start_test_mode_231):
updated use of wait_for_interrupt
2011-06-21 01:58:31 +03:00
|
|
|
IRQ_TRX_END | IRQ_RX_START | IRQ_PLL_LOCK, wait_ms);
|
2011-01-20 20:23:56 +02:00
|
|
|
if (!run)
|
|
|
|
return rx_exit;
|
|
|
|
if (!irq)
|
|
|
|
return rx_timeout;
|
|
|
|
|
|
|
|
n = atrf_buf_read(dsc, pck, sizeof(*pck));
|
|
|
|
if (n < 0)
|
|
|
|
exit(1);
|
|
|
|
if (n != sizeof(*pck)) {
|
|
|
|
fprintf(stderr, "%d bytes received\n", n);
|
|
|
|
return rx_bad;
|
|
|
|
}
|
|
|
|
return atrf_reg_read(dsc, REG_PHY_RSSI) & RX_CRC_VALID ?
|
|
|
|
rx_good : rx_bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void ping(struct atrf_dsc *dsc, double max_wait_s, int master)
|
|
|
|
{
|
|
|
|
static int first = 1;
|
|
|
|
struct ping tx_pck = {
|
|
|
|
.seq = 0,
|
|
|
|
.ack = 0,
|
|
|
|
};
|
|
|
|
struct ping rx_pck;
|
|
|
|
enum rx_res res;
|
|
|
|
|
|
|
|
while (run) {
|
|
|
|
tx_pck.seq++;
|
|
|
|
if (master || !first) {
|
|
|
|
ping_tx(dsc, &tx_pck);
|
|
|
|
if (!run)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
first = 0;
|
tools/: major overhaul of wait_for_interrupt; uses atrf_interrupt_wait now
- include/misctxrx.h (wait_for_interrupt), lib/misctxrx.c
(wait_for_interrupt): replaced sleep_us*timeout limiting mechanism
with a single timeout value in milliseconds
- lib/misctxrx.c (wait_for_interrupt): use atrf_interrupt_wait instead
of polling
- lib/misctxrx.c (wait_for_interrupt): cleaned up control flow
- lib/misctxrx.c (run, die, wait_for_interrupt): renamed variable "run"
to more specific "sigint"
- atrf-txrx/atrf-txrx.c (ping_rx, ping): pass timeout in milliseconds,
not deciseconds
- atrf-rssi/atrf-rssi.c (sweep), atrf-rssi/gui.c (sweep),
atrf-txrx/atrf-txrx.c (init_txrx, receive_message, receive_pcap,
receive, transmit, transmit_pattern, ping_tx, ping_rx),
atrf-xmit/atrf-xmit.c (init_tx, init_rx, xfer_one),
lib/cwtest.c (enter_test_mode_230, start_test_mode_231):
updated use of wait_for_interrupt
2011-06-21 01:58:31 +03:00
|
|
|
res = ping_rx(dsc, &rx_pck, master ? max_wait_s*1000 : 0);
|
2011-01-20 20:23:56 +02:00
|
|
|
switch (res) {
|
|
|
|
case rx_good:
|
|
|
|
tx_pck.ack = rx_pck.seq;
|
|
|
|
if (tx_pck.seq == rx_pck.ack)
|
|
|
|
write(2, ".", 1);
|
|
|
|
else
|
|
|
|
write(2, "*", 1);
|
|
|
|
break;
|
|
|
|
case rx_bad:
|
|
|
|
write(2, "-", 1);
|
|
|
|
break;
|
|
|
|
case rx_timeout:
|
|
|
|
write(2, "+", 1);
|
|
|
|
break;
|
|
|
|
case rx_exit:
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-07 19:59:23 +02:00
|
|
|
static int test_mode(struct atrf_dsc *dsc, uint8_t cont_tx, const char *cmd)
|
|
|
|
{
|
|
|
|
int status = 0;
|
|
|
|
|
2011-04-10 16:24:24 +03:00
|
|
|
cw_test_begin(dsc, cont_tx);
|
2010-11-11 07:32:09 +02:00
|
|
|
|
2010-11-12 02:31:15 +02:00
|
|
|
if (cmd)
|
|
|
|
status = system(cmd);
|
|
|
|
else {
|
|
|
|
while (run)
|
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
|
2011-04-10 16:24:24 +03:00
|
|
|
cw_test_end(dsc);
|
2010-11-12 02:31:15 +02:00
|
|
|
|
|
|
|
return status;
|
2010-11-11 07:32:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-14 23:12:03 +03:00
|
|
|
static void die(int sig)
|
|
|
|
{
|
|
|
|
run = 0;
|
2010-08-24 12:16:48 +03:00
|
|
|
}
|
2010-08-21 07:42:58 +03:00
|
|
|
|
|
|
|
|
|
|
|
static void usage(const char *name)
|
|
|
|
{
|
2010-08-24 12:16:48 +03:00
|
|
|
fprintf(stderr,
|
2011-01-19 06:11:48 +02:00
|
|
|
"usage: %s [common_options] [message [repetitions]]\n"
|
2011-07-12 19:32:18 +03:00
|
|
|
" %s [common_options] -H [message]\n"
|
2011-01-20 17:41:49 +02:00
|
|
|
" %s [common_options] -E pause_s [repetitions]\n"
|
2011-01-20 20:23:56 +02:00
|
|
|
" %s [common_options] -P [max_wait_s]\n"
|
2011-01-19 06:11:48 +02:00
|
|
|
" %s [common_options] -T offset [command]\n\n"
|
|
|
|
" text message mode:\n"
|
2010-11-12 02:31:15 +02:00
|
|
|
" message message string to send (if absent, receive)\n"
|
2011-01-19 06:11:48 +02:00
|
|
|
" repetitions number of times the message is sent (default 1)\n\n"
|
2011-07-12 19:32:18 +03:00
|
|
|
" text message mode (hard MAC):\n"
|
|
|
|
" -H use hard MAC mode\n"
|
|
|
|
" message message string to send (if absent, receive)\n"
|
2011-01-19 22:26:27 +02:00
|
|
|
" PER test mode (transmit only):\n"
|
2011-01-20 17:41:49 +02:00
|
|
|
" -E pause_s seconds to pause between frames (floating-point)\n"
|
2011-01-19 17:24:20 +02:00
|
|
|
" repetitions number of messages to send (default: infinite)\n\n"
|
2011-01-20 20:23:56 +02:00
|
|
|
" Ping-pong mode:\n"
|
|
|
|
" -P exchange packets between two stations\n"
|
|
|
|
" max_wait_s generate a new packet if no response is received (master)\n\n"
|
2011-01-19 06:11:48 +02:00
|
|
|
" constant wave test mode (transmit only):\n"
|
|
|
|
" -T offset test mode. offset is the frequency offset of the constant\n"
|
|
|
|
" wave in MHz: -2, -0.5, or +0.5\n"
|
2010-11-12 02:31:15 +02:00
|
|
|
" command shell command to run while transmitting (default: wait for\n"
|
|
|
|
" SIGINT instead)\n\n"
|
tools/: added option -d driver[:arg] to all tools
- atrf-id/atrf-id.c (main), atrf-reset/atrf-reset.c (main),
atrf-trim/atrf-trim.c (main): changed command-line parsing to use
"getopt"
- atrf-id/atrf-id.c (usage, main), atrf-reset/atrf-reset.c (usage, main),
atrf-rssi/atrf-rssi.c (usage, main), atrf-trim/atrf-trim.c (usage,
main), atrf-txrx/atrf-txrx.c (init_txrx, usage, main),
atrf-xtal/atrf-xtal.c (usage, main): added option -d to select a driver
2011-04-10 13:13:53 +03:00
|
|
|
" common options: [-c channel|-f freq] [-C mhz] [-d driver[:arg]] [-o file]\n"
|
|
|
|
" [-p power] [-r rate] [-t trim]\n"
|
2010-11-12 02:31:15 +02:00
|
|
|
" -c channel channel number, 11 to 26 (default %d)\n"
|
2011-01-13 00:13:21 +02:00
|
|
|
" -C mhz output clock at 1, 2, 4, 8, or 16 MHz (default: off)\n"
|
tools/: added option -d driver[:arg] to all tools
- atrf-id/atrf-id.c (main), atrf-reset/atrf-reset.c (main),
atrf-trim/atrf-trim.c (main): changed command-line parsing to use
"getopt"
- atrf-id/atrf-id.c (usage, main), atrf-reset/atrf-reset.c (usage, main),
atrf-rssi/atrf-rssi.c (usage, main), atrf-trim/atrf-trim.c (usage,
main), atrf-txrx/atrf-txrx.c (init_txrx, usage, main),
atrf-xtal/atrf-xtal.c (usage, main): added option -d to select a driver
2011-04-10 13:13:53 +03:00
|
|
|
" -d driver[:arg]\n"
|
|
|
|
" use the specified driver (default: %s)\n"
|
2010-11-12 02:31:15 +02:00
|
|
|
" -f freq frequency in MHz, 2405 to 2480 (default %d)\n"
|
2011-01-19 08:22:24 +02:00
|
|
|
" -o file write received data to a file in pcap format\n"
|
2010-11-12 02:31:15 +02:00
|
|
|
" -p power transmit power, -17.2 to 3.0 dBm (default %.1f)\n"
|
2011-01-21 00:32:40 +02:00
|
|
|
" -r rate data rate, 250k, 500k, 1M, or 2M (default: 250k)\n"
|
2011-03-04 04:18:43 +02:00
|
|
|
" -t trim trim capacitor, 0 to 15 (default %d)\n"
|
2011-07-12 19:32:18 +03:00
|
|
|
, name, name, name, name, name,
|
tools/: added option -d driver[:arg] to all tools
- atrf-id/atrf-id.c (main), atrf-reset/atrf-reset.c (main),
atrf-trim/atrf-trim.c (main): changed command-line parsing to use
"getopt"
- atrf-id/atrf-id.c (usage, main), atrf-reset/atrf-reset.c (usage, main),
atrf-rssi/atrf-rssi.c (usage, main), atrf-trim/atrf-trim.c (usage,
main), atrf-txrx/atrf-txrx.c (init_txrx, usage, main),
atrf-xtal/atrf-xtal.c (usage, main): added option -d to select a driver
2011-04-10 13:13:53 +03:00
|
|
|
DEFAULT_CHANNEL, atrf_default_driver_name(),
|
|
|
|
2405+5*(DEFAULT_CHANNEL-11), DEFAULT_POWER,
|
2011-03-04 04:18:43 +02:00
|
|
|
DEFAULT_TRIM);
|
2010-08-21 07:42:58 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-12 15:47:12 +02:00
|
|
|
static void set_mode(enum mode *mode, enum mode new)
|
|
|
|
{
|
|
|
|
if (*mode == mode_msg) {
|
|
|
|
*mode = new;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fprintf(stderr, "multiple mode selections\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-24 12:16:48 +03:00
|
|
|
int main(int argc, char *const *argv)
|
2010-08-21 07:42:58 +03:00
|
|
|
{
|
2013-02-12 15:47:12 +02:00
|
|
|
enum mode mode = mode_msg;
|
tools/: added option -d driver[:arg] to all tools
- atrf-id/atrf-id.c (main), atrf-reset/atrf-reset.c (main),
atrf-trim/atrf-trim.c (main): changed command-line parsing to use
"getopt"
- atrf-id/atrf-id.c (usage, main), atrf-reset/atrf-reset.c (usage, main),
atrf-rssi/atrf-rssi.c (usage, main), atrf-trim/atrf-trim.c (usage,
main), atrf-txrx/atrf-txrx.c (init_txrx, usage, main),
atrf-xtal/atrf-xtal.c (usage, main): added option -d to select a driver
2011-04-10 13:13:53 +03:00
|
|
|
const char *driver = NULL;
|
2010-08-24 12:16:48 +03:00
|
|
|
int channel = DEFAULT_CHANNEL;
|
|
|
|
double power = DEFAULT_POWER;
|
2011-01-21 00:32:40 +02:00
|
|
|
uint8_t rate = OQPSK_DATA_RATE_250;
|
2011-03-04 04:18:43 +02:00
|
|
|
int trim = DEFAULT_TRIM, times = 1;
|
2010-11-11 07:32:09 +02:00
|
|
|
uint8_t cont_tx = 0;
|
2011-01-19 17:24:20 +02:00
|
|
|
double pause_s = 0;
|
2010-08-24 12:16:48 +03:00
|
|
|
char *end;
|
2010-11-11 07:44:33 +02:00
|
|
|
int c, freq;
|
2011-02-11 04:11:34 +02:00
|
|
|
unsigned clkm = 0;
|
2010-11-12 02:31:15 +02:00
|
|
|
int status = 0;
|
2011-01-19 08:22:24 +02:00
|
|
|
const char *pcap_file = NULL;
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
struct atrf_dsc *dsc;
|
2010-08-21 07:42:58 +03:00
|
|
|
|
2011-07-12 19:32:18 +03:00
|
|
|
while ((c = getopt(argc, argv, "c:C:d:f:Ho:p:r:E:Pt:T:")) != EOF)
|
2010-08-24 12:16:48 +03:00
|
|
|
switch (c) {
|
|
|
|
case 'c':
|
|
|
|
channel = strtoul(optarg, &end, 0);
|
|
|
|
if (*end)
|
|
|
|
usage(*argv);
|
|
|
|
if (channel < 11 || channel > 26)
|
|
|
|
usage(*argv);
|
|
|
|
break;
|
tools/: added option -d driver[:arg] to all tools
- atrf-id/atrf-id.c (main), atrf-reset/atrf-reset.c (main),
atrf-trim/atrf-trim.c (main): changed command-line parsing to use
"getopt"
- atrf-id/atrf-id.c (usage, main), atrf-reset/atrf-reset.c (usage, main),
atrf-rssi/atrf-rssi.c (usage, main), atrf-trim/atrf-trim.c (usage,
main), atrf-txrx/atrf-txrx.c (init_txrx, usage, main),
atrf-xtal/atrf-xtal.c (usage, main): added option -d to select a driver
2011-04-10 13:13:53 +03:00
|
|
|
case 'd':
|
|
|
|
driver = optarg;
|
|
|
|
break;
|
2010-11-11 07:44:33 +02:00
|
|
|
case 'f':
|
|
|
|
freq = strtoul(optarg, &end, 0);
|
|
|
|
if (*end)
|
|
|
|
usage(*argv);
|
|
|
|
if (freq % 5)
|
|
|
|
usage(*argv);
|
|
|
|
channel = (freq-2405)/5+11;
|
|
|
|
if (channel < 11 || channel > 26)
|
|
|
|
usage(*argv);
|
|
|
|
break;
|
2011-07-12 19:32:18 +03:00
|
|
|
case 'H':
|
2013-02-12 15:47:12 +02:00
|
|
|
set_mode(&mode, mode_hmac);
|
2011-07-12 19:32:18 +03:00
|
|
|
break;
|
2011-01-19 08:22:24 +02:00
|
|
|
case 'o':
|
|
|
|
pcap_file = optarg;
|
|
|
|
break;
|
2010-08-24 12:16:48 +03:00
|
|
|
case 'p':
|
|
|
|
power = strtod(optarg, &end);
|
|
|
|
if (*end)
|
|
|
|
usage(*argv);
|
|
|
|
break;
|
2011-01-21 00:32:40 +02:00
|
|
|
case 'r':
|
|
|
|
if (!strcmp(optarg, "250k"))
|
|
|
|
rate = OQPSK_DATA_RATE_250;
|
|
|
|
else if (!strcmp(optarg, "500k"))
|
|
|
|
rate = OQPSK_DATA_RATE_500;
|
|
|
|
else if (!strcmp(optarg, "1M"))
|
|
|
|
rate = OQPSK_DATA_RATE_1000;
|
|
|
|
else if (!strcmp(optarg, "2M"))
|
|
|
|
rate = OQPSK_DATA_RATE_2000;
|
|
|
|
else
|
|
|
|
usage(*argv);
|
|
|
|
break;
|
2010-08-24 12:16:48 +03:00
|
|
|
case 't':
|
|
|
|
trim = strtoul(optarg, &end, 0);
|
|
|
|
if (*end)
|
|
|
|
usage(*argv);
|
|
|
|
if (trim > 15)
|
|
|
|
usage(*argv);
|
|
|
|
break;
|
2011-01-13 00:13:21 +02:00
|
|
|
case 'C':
|
2011-02-11 04:11:34 +02:00
|
|
|
clkm = strtol(optarg, &end, 0);
|
2011-01-13 00:13:21 +02:00
|
|
|
if (*end)
|
|
|
|
usage(*argv);
|
2011-02-11 04:11:34 +02:00
|
|
|
if (!clkm)
|
2011-01-13 00:13:21 +02:00
|
|
|
usage(*argv);
|
|
|
|
break;
|
2011-01-20 17:41:49 +02:00
|
|
|
case 'E':
|
2013-02-12 15:47:12 +02:00
|
|
|
set_mode(&mode, mode_per);
|
2011-01-19 22:26:27 +02:00
|
|
|
pause_s = strtof(optarg, &end);
|
|
|
|
if (*end)
|
|
|
|
usage(*argv);
|
|
|
|
break;
|
2011-01-20 20:23:56 +02:00
|
|
|
case 'P':
|
2013-02-12 15:47:12 +02:00
|
|
|
set_mode(&mode, mode_ping);
|
2011-01-20 20:23:56 +02:00
|
|
|
break;
|
2010-11-11 07:32:09 +02:00
|
|
|
case 'T':
|
2013-02-12 15:47:12 +02:00
|
|
|
set_mode(&mode, mode_cont_tx);
|
2010-11-11 07:32:09 +02:00
|
|
|
if (!strcmp(optarg, "-2"))
|
|
|
|
cont_tx = CONT_TX_M2M;
|
|
|
|
else if (!strcmp(optarg, "-0.5"))
|
|
|
|
cont_tx = CONT_TX_M500K;
|
|
|
|
else if (!strcmp(optarg, "+0.5"))
|
|
|
|
cont_tx = CONT_TX_P500K;
|
|
|
|
else
|
|
|
|
usage(*argv);
|
|
|
|
break;
|
2010-08-24 12:16:48 +03:00
|
|
|
default:
|
|
|
|
usage(*argv);
|
|
|
|
}
|
2010-08-21 07:42:58 +03:00
|
|
|
|
2010-09-14 23:12:03 +03:00
|
|
|
signal(SIGINT, die);
|
|
|
|
|
2010-08-24 12:16:48 +03:00
|
|
|
switch (argc-optind) {
|
|
|
|
case 0:
|
tools/: added option -d driver[:arg] to all tools
- atrf-id/atrf-id.c (main), atrf-reset/atrf-reset.c (main),
atrf-trim/atrf-trim.c (main): changed command-line parsing to use
"getopt"
- atrf-id/atrf-id.c (usage, main), atrf-reset/atrf-reset.c (usage, main),
atrf-rssi/atrf-rssi.c (usage, main), atrf-trim/atrf-trim.c (usage,
main), atrf-txrx/atrf-txrx.c (init_txrx, usage, main),
atrf-xtal/atrf-xtal.c (usage, main): added option -d to select a driver
2011-04-10 13:13:53 +03:00
|
|
|
dsc = init_txrx(driver, trim, clkm);
|
Merged uSD driver into unified tool build, completed conversion of tools.
- atusd/tools/lib/atusd.c: moved to tools/lib/
- atusd/tools/lib/atusd.h: removed, we can now use tools/include/atspi.h
- tools/lib/atusd.c: added copyright header
- tools/lib/atusd.c: updated for driver API
- tools/lib/Makefile: added atusd.o
- tools/Makefile.common: moved common elements from all other makefiles in
tools/*/ here
- tools/Makefile.common: added target-specific compiler and flags
- tools/atspi-id/Makefile, tools/atspi-reset/Makefile,
tools/atspi-rssi/Makefile, tools/atspi-trim/Makefile,
tools/atspi-txrx/Makefile, tools/lib/Makefile: used Makefile.common
- tools/lib/Makefile: differentiate USB and uSD build
- tools/atspi-id/atspi-id.c, tools/atspi-reset/atspi-reset.c,
tools/atspi-rssi/atspi-rssi.c, tools/atspi-trim/atspi-trim.c,
tools/atspi-txr/atspi-txr.c: updated for driver-agnostic API
- tools/atspi-id/atspi-id.c, tools/atspi-reset/atspi-reset.c,
tools/atspi-rssi/atspi-rssi.c, tools/atspi-trim/atspi-trim.c,
tools/atspi-txr/atspi-txr.c: corrected AF86RF230 typo in title
- tools/include/atspi.h, tools/lib/atspi.c, tools/lib/driver.c,
tools/lib/atusb.c: brought back support for atspi_error and
atspi_clear_error
- tools/atspi-id/atspi-id.c (atspi_get_protocol): renamed to get_protocol,
to make it clear that it's not from libatspi
- tools/atspi-id/atspi-id.c (atspi_get_build): renamed to get_build, to
make it clear that it's not from libatspi
- tools/include/atspi.h, tools/lib/atspi.c (atspi_usb_handle): new function
to obtain a driver's USB device handle (or NULL if the driver doesn't use
USB)
2010-09-06 02:32:58 +03:00
|
|
|
set_channel(dsc, channel);
|
2011-01-21 00:32:40 +02:00
|
|
|
set_rate(dsc, rate);
|
2011-01-19 17:24:20 +02:00
|
|
|
switch (mode) {
|
|
|
|
case mode_msg:
|
2011-01-19 08:22:24 +02:00
|
|
|
receive(dsc, pcap_file);
|
2011-01-19 17:24:20 +02:00
|
|
|
break;
|
2011-07-12 19:32:18 +03:00
|
|
|
case mode_hmac:
|
|
|
|
receive_hmac(dsc);
|
|
|
|
break;
|
2011-01-19 22:26:27 +02:00
|
|
|
case mode_per:
|
2011-04-12 22:37:05 +03:00
|
|
|
set_power_dBm(dsc, power, 0);
|
2011-01-19 17:24:20 +02:00
|
|
|
transmit_pattern(dsc, pause_s, 0);
|
|
|
|
break;
|
2011-01-20 20:23:56 +02:00
|
|
|
case mode_ping:
|
2011-04-12 22:37:05 +03:00
|
|
|
set_power_dBm(dsc, power, 1);
|
2011-01-20 20:23:56 +02:00
|
|
|
ping(dsc, pause_s, 0);
|
|
|
|
break;
|
2011-01-19 17:24:20 +02:00
|
|
|
case mode_cont_tx:
|
2011-04-12 22:37:05 +03:00
|
|
|
set_power_dBm(dsc, power, 0);
|
2010-11-12 02:31:15 +02:00
|
|
|
status = test_mode(dsc, cont_tx, NULL);
|
2011-01-19 17:24:20 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
2010-11-11 07:32:09 +02:00
|
|
|
}
|
2010-08-24 12:16:48 +03:00
|
|
|
break;
|
2010-09-14 23:12:03 +03:00
|
|
|
case 2:
|
2011-01-19 17:24:20 +02:00
|
|
|
switch (mode) {
|
|
|
|
case mode_msg:
|
2011-07-12 19:32:18 +03:00
|
|
|
case mode_hmac:
|
2011-01-19 17:24:20 +02:00
|
|
|
break;
|
2011-01-19 22:26:27 +02:00
|
|
|
case mode_per:
|
2011-01-20 20:23:56 +02:00
|
|
|
case mode_ping:
|
2011-01-19 17:24:20 +02:00
|
|
|
/* fall through */
|
|
|
|
case mode_cont_tx:
|
2010-11-12 02:31:15 +02:00
|
|
|
usage(*argv);
|
2011-01-19 17:24:20 +02:00
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
2010-09-14 23:12:03 +03:00
|
|
|
times = strtoul(argv[optind+1], &end, 0);
|
|
|
|
if (*end)
|
|
|
|
usage(*argv);
|
|
|
|
/* fall through */
|
2010-08-24 12:16:48 +03:00
|
|
|
case 1:
|
tools/: added option -d driver[:arg] to all tools
- atrf-id/atrf-id.c (main), atrf-reset/atrf-reset.c (main),
atrf-trim/atrf-trim.c (main): changed command-line parsing to use
"getopt"
- atrf-id/atrf-id.c (usage, main), atrf-reset/atrf-reset.c (usage, main),
atrf-rssi/atrf-rssi.c (usage, main), atrf-trim/atrf-trim.c (usage,
main), atrf-txrx/atrf-txrx.c (init_txrx, usage, main),
atrf-xtal/atrf-xtal.c (usage, main): added option -d to select a driver
2011-04-10 13:13:53 +03:00
|
|
|
dsc = init_txrx(driver, trim, clkm);
|
Merged uSD driver into unified tool build, completed conversion of tools.
- atusd/tools/lib/atusd.c: moved to tools/lib/
- atusd/tools/lib/atusd.h: removed, we can now use tools/include/atspi.h
- tools/lib/atusd.c: added copyright header
- tools/lib/atusd.c: updated for driver API
- tools/lib/Makefile: added atusd.o
- tools/Makefile.common: moved common elements from all other makefiles in
tools/*/ here
- tools/Makefile.common: added target-specific compiler and flags
- tools/atspi-id/Makefile, tools/atspi-reset/Makefile,
tools/atspi-rssi/Makefile, tools/atspi-trim/Makefile,
tools/atspi-txrx/Makefile, tools/lib/Makefile: used Makefile.common
- tools/lib/Makefile: differentiate USB and uSD build
- tools/atspi-id/atspi-id.c, tools/atspi-reset/atspi-reset.c,
tools/atspi-rssi/atspi-rssi.c, tools/atspi-trim/atspi-trim.c,
tools/atspi-txr/atspi-txr.c: updated for driver-agnostic API
- tools/atspi-id/atspi-id.c, tools/atspi-reset/atspi-reset.c,
tools/atspi-rssi/atspi-rssi.c, tools/atspi-trim/atspi-trim.c,
tools/atspi-txr/atspi-txr.c: corrected AF86RF230 typo in title
- tools/include/atspi.h, tools/lib/atspi.c, tools/lib/driver.c,
tools/lib/atusb.c: brought back support for atspi_error and
atspi_clear_error
- tools/atspi-id/atspi-id.c (atspi_get_protocol): renamed to get_protocol,
to make it clear that it's not from libatspi
- tools/atspi-id/atspi-id.c (atspi_get_build): renamed to get_build, to
make it clear that it's not from libatspi
- tools/include/atspi.h, tools/lib/atspi.c (atspi_usb_handle): new function
to obtain a driver's USB device handle (or NULL if the driver doesn't use
USB)
2010-09-06 02:32:58 +03:00
|
|
|
set_channel(dsc, channel);
|
2011-01-21 00:32:40 +02:00
|
|
|
set_rate(dsc, rate);
|
2011-01-19 17:24:20 +02:00
|
|
|
switch (mode) {
|
|
|
|
case mode_msg:
|
2011-04-12 22:37:05 +03:00
|
|
|
set_power_dBm(dsc, power, 1);
|
2010-11-12 02:31:15 +02:00
|
|
|
transmit(dsc, argv[optind], times);
|
2011-01-19 17:24:20 +02:00
|
|
|
break;
|
2011-07-12 19:32:18 +03:00
|
|
|
case mode_hmac:
|
|
|
|
set_power_dBm(dsc, power, 1);
|
|
|
|
transmit_hmac(dsc, argv[optind]);
|
|
|
|
break;
|
2011-01-19 22:26:27 +02:00
|
|
|
case mode_per:
|
2011-04-19 10:51:18 +03:00
|
|
|
times = strtoul(argv[optind], &end, 0);
|
2011-01-19 17:24:20 +02:00
|
|
|
if (*end)
|
|
|
|
usage(*argv);
|
2011-04-12 22:37:05 +03:00
|
|
|
set_power_dBm(dsc, power, 0);
|
2011-01-19 17:24:20 +02:00
|
|
|
transmit_pattern(dsc, pause_s, times);
|
|
|
|
break;
|
2011-01-20 20:23:56 +02:00
|
|
|
case mode_ping:
|
|
|
|
pause_s = strtof(argv[optind], &end);
|
|
|
|
if (*end)
|
|
|
|
usage(*argv);
|
2011-04-12 22:37:05 +03:00
|
|
|
set_power_dBm(dsc, power, 1);
|
2011-01-20 20:23:56 +02:00
|
|
|
ping(dsc, pause_s, 1);
|
|
|
|
break;
|
2011-01-19 17:24:20 +02:00
|
|
|
case mode_cont_tx:
|
2011-04-12 22:37:05 +03:00
|
|
|
set_power_dBm(dsc, power, 0);
|
2010-11-12 02:31:15 +02:00
|
|
|
status = test_mode(dsc, cont_tx, argv[optind]);
|
2011-01-19 17:24:20 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
|
2010-11-12 02:31:15 +02:00
|
|
|
}
|
2010-08-24 12:16:48 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage(*argv);
|
|
|
|
}
|
2010-08-21 07:42:58 +03:00
|
|
|
|
The Great ATSPI Renaming, part 6: change atrf API from atspi_* to atrf_*
- include/atrf.h, lib/atrf.c (struct atspi_dsc): renamed to "struct
atrf_dsc"
- include/atrf.h, lib/atrf.c (atspi_*): renamed all functions to atrf_*
- include/misctxrx.h, lib/misctxrx.c (wait_for_interrupt): updated for API
name change
- atspi-id/atspi-id.c (show_usb_info, show_info, main),
atspi-reset/atspi-reset.c (main), atspi-rssi/atspi-rssi.c (sweep, main),
atspi-rssi/gui.h (gui), atspi-rssi/gui.c (sweep, gui),
atspi-trim/atspi-trim.c (main), atspi-txrx/atspi-txrx.c (init_txrx,
set_channel, set_power, receive, transmit, test_mode, main):
updated for API name change
2010-11-11 15:10:13 +02:00
|
|
|
atrf_close(dsc);
|
2010-09-09 23:23:47 +03:00
|
|
|
|
2010-11-12 02:31:15 +02:00
|
|
|
if (status) {
|
|
|
|
if (WIFEXITED(status))
|
|
|
|
return WEXITSTATUS(status);
|
|
|
|
if (WIFSIGNALED(status))
|
|
|
|
raise(WTERMSIG(status));
|
|
|
|
fprintf(stderr, "unexpected exit status %d\n", status);
|
|
|
|
abort();
|
|
|
|
}
|
2010-08-21 07:42:58 +03:00
|
|
|
return 0;
|
|
|
|
}
|