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 a7a94b85cd782d9e56cbbe3f44db29b6f4e0bdbe created 13 years 4 months ago. By Werner Almesberger, Use getopt in atspi-rssi.c | |
---|---|
1 | /* |
2 | * atspi-rssi/atspi-rssi.c - ben-wpan AT86RF230 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 <unistd.h> |
17 | #include <signal.h> |
18 | #include <sys/time.h> |
19 | |
20 | #include "at86rf230.h" |
21 | #include "atspi.h" |
22 | #include "misctxrx.h" |
23 | |
24 | |
25 | static struct timeval t0; |
26 | static volatile int run = 1; |
27 | |
28 | |
29 | static void sweep(struct atspi_dsc *dsc) |
30 | { |
31 | int chan, rssi; |
32 | struct timeval t; |
33 | |
34 | for (chan = 11; chan <= 26; chan++) { |
35 | atspi_reg_write(dsc, REG_PHY_CC_CCA, chan); |
36 | /* 150 us, according to AVR2001 section 3.5 */ |
37 | wait_for_interrupt(dsc, IRQ_PLL_LOCK, IRQ_PLL_LOCK, 10, 20); |
38 | |
39 | gettimeofday(&t, NULL); |
40 | rssi = atspi_reg_read(dsc, REG_PHY_RSSI) & RSSI_MASK; |
41 | t.tv_sec -= t0.tv_sec; |
42 | t.tv_usec -= t0.tv_usec; |
43 | printf("%d %f %d\n", |
44 | 2405+(chan-11)*5, |
45 | (double) t.tv_sec+t.tv_usec/1000000.0, |
46 | -91+3*(rssi-1)); |
47 | } |
48 | printf("\n"); |
49 | } |
50 | |
51 | |
52 | static void die(int sig) |
53 | { |
54 | run = 0; |
55 | } |
56 | |
57 | |
58 | static void usage(const char *name) |
59 | { |
60 | fprintf(stderr, |
61 | "usage: %s [-n] sweeps\n", name); |
62 | exit(1); |
63 | } |
64 | |
65 | |
66 | int main(int argc, char **argv) |
67 | { |
68 | struct atspi_dsc *dsc; |
69 | unsigned long sweeps, i; |
70 | char *end; |
71 | int c; |
72 | |
73 | while ((c = getopt(argc, argv, "n")) != EOF) |
74 | switch (c) { |
75 | case 'n': |
76 | break; |
77 | default: |
78 | usage(*argv); |
79 | } |
80 | |
81 | switch (argc-optind) { |
82 | case 1: |
83 | sweeps = strtoul(argv[optind], &end, 0); |
84 | if (*end) |
85 | usage(*argv); |
86 | break; |
87 | default: |
88 | usage(*argv); |
89 | } |
90 | |
91 | signal(SIGINT, die); |
92 | |
93 | dsc = atspi_open(); |
94 | if (!dsc) |
95 | return 1; |
96 | |
97 | atspi_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TRX_OFF); |
98 | atspi_reg_write(dsc, REG_TRX_STATE, TRX_CMD_RX_ON); |
99 | /* |
100 | * We'll wait for the PLL lock after selecting the channel. |
101 | */ |
102 | |
103 | gettimeofday(&t0, NULL); |
104 | for (i = 0; run && i != sweeps; i++) |
105 | sweep(dsc); |
106 | |
107 | atspi_reg_write(dsc, REG_TRX_STATE, TRX_CMD_TRX_OFF); |
108 | |
109 | atspi_close(dsc); |
110 | |
111 | return 0; |
112 | } |
113 |