IEEE 802.15.4 subsystem
Sign in or create your account | Project List | Help
IEEE 802.15.4 subsystem Git Source Tree
Root/
Source at commit b7700518d9a2276137e51c7ed8de8373a43007f9 created 13 years 7 months ago. By Werner Almesberger, atspi-trim: utility to set the crystal trimming capacitors. | |
---|---|
1 | /* |
2 | * atspi-rssi/atspi-rssi.c - ben-wpan AF86RF230 spectrum scan |
3 | * |
4 | * Written 2010 by Werner Almesberger |
5 | * Copyright 2010 Werner Almesberger |
6 | * |
7 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. |
11 | */ |
12 | |
13 | |
14 | #include <stdlib.h> |
15 | #include <stdio.h> |
16 | #include <usb.h> |
17 | #include <sys/time.h> |
18 | |
19 | #include "at86rf230.h" |
20 | #include "atspi/ep0.h" |
21 | #include "atspi.h" |
22 | |
23 | |
24 | static struct timeval t0; |
25 | |
26 | |
27 | static void sweep(usb_dev_handle *dev) |
28 | { |
29 | int chan, rssi; |
30 | struct timeval t; |
31 | |
32 | for (chan = 11; chan <= 26; chan++) { |
33 | atspi_reg_write(dev, REG_PHY_CC_CCA, chan); |
34 | /* |
35 | * No need to explicitly wait for the PPL lock - going USB-SPI |
36 | * is pretty slow, leaving the transceiver plenty of time. |
37 | */ |
38 | gettimeofday(&t, NULL); |
39 | rssi = atspi_reg_read(dev, REG_PHY_RSSI) & RSSI_MASK; |
40 | t.tv_sec -= t0.tv_sec; |
41 | t.tv_usec -= t0.tv_usec; |
42 | printf("%d %f %d\n", |
43 | 2405+(chan-11)*5, |
44 | (double) t.tv_sec+t.tv_usec/1000000.0, |
45 | -91+3*(rssi-1)); |
46 | } |
47 | printf("\n"); |
48 | } |
49 | |
50 | |
51 | static void usage(const char *name) |
52 | { |
53 | fprintf(stderr, "%s sweeps \n", name); |
54 | exit(1); |
55 | } |
56 | |
57 | |
58 | int main(int argc, const char **argv) |
59 | { |
60 | usb_dev_handle *dev; |
61 | unsigned long sweeps, i; |
62 | char *end; |
63 | |
64 | if (argc != 2) |
65 | usage(*argv); |
66 | sweeps = strtoul(argv[1], &end, 0); |
67 | if (*end) |
68 | usage(*argv); |
69 | |
70 | dev = atspi_open(); |
71 | if (!dev) |
72 | return 1; |
73 | |
74 | atspi_reg_write(dev, REG_TRX_STATE, TRX_CMD_TRX_OFF); |
75 | /* |
76 | * No need to explicitly wait for things to stabilize - going USB-SPI |
77 | * is pretty slow, leaving the transceiver more than enough time. |
78 | */ |
79 | atspi_reg_write(dev, REG_TRX_STATE, TRX_CMD_RX_ON); |
80 | |
81 | gettimeofday(&t0, NULL); |
82 | for (i = 0; i != sweeps; i++) |
83 | sweep(dev); |
84 | |
85 | atspi_reg_write(dev, REG_TRX_STATE, TRX_CMD_TRX_OFF); |
86 | |
87 | return 0; |
88 | } |
89 |