xbee: add a new module
[aversive.git] / modules / devices / radio / xbee / xbee_stats.c
1 /*
2  * Copyright (c) 2011, Olivier MATZ <zer0@droids-corp.org>
3  * All rights reserved.
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  *     * Redistributions of source code must retain the above copyright
8  *       notice, this list of conditions and the following disclaimer.
9  *     * Redistributions in binary form must reproduce the above copyright
10  *       notice, this list of conditions and the following disclaimer in the
11  *       documentation and/or other materials provided with the distribution.
12  *     * Neither the name of the University of California, Berkeley nor the
13  *       names of its contributors may be used to endorse or promote products
14  *       derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27
28 #include <aversive.h>
29 #include <aversive/pgmspace.h>
30 #include <aversive/queue.h>
31
32 #include <string.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <stdint.h>
36
37 #include "xbee_neighbor.h"
38 #include "xbee_stats.h"
39 #include "xbee_rxtx.h"
40 #include "xbee.h"
41
42 struct xbee_stats *xbee_get_stats(struct xbee_dev *dev)
43 {
44 #ifdef CONFIG_MODULE_XBEE_STATS
45         return &dev->stats;
46 #else
47         (void)dev;
48         return NULL;
49 #endif
50 }
51
52 void xbee_reset_stats(struct xbee_dev *dev)
53 {
54         (void)dev;
55 #ifdef CONFIG_MODULE_XBEE_STATS
56         memset(&dev->stats, 0, sizeof(dev->stats));
57 #endif
58 }
59
60 void xbee_dump_stats(struct xbee_dev *dev)
61 {
62 #ifdef CONFIG_MODULE_XBEE_STATS
63         printf_P(PSTR("statistics on xbee_dev %p:\r\n"), dev);
64         printf_P(PSTR(" rx_frame: %"PRIu32"\r\n"), dev->stats.rx_frame);
65         printf_P(PSTR(" rx_atresp: %"PRIu32"\r\n"), dev->stats.rx_atresp);
66         printf_P(PSTR(" rx_atresp_error: %"PRIu32"\r\n"), dev->stats.rx_atresp_error);
67         printf_P(PSTR(" rx_modem_status: %"PRIu32"\r\n"), dev->stats.rx_modem_status);
68         printf_P(PSTR(" rx_xmit_status: %"PRIu32"\r\n"), dev->stats.rx_xmit_status);
69         printf_P(PSTR(" rx_xmit_status_error: %"PRIu32"\r\n"), dev->stats.rx_xmit_status_error);
70         printf_P(PSTR(" rx_data: %"PRIu32"\r\n"), dev->stats.rx_data);
71         printf_P(PSTR(" rx_expl_data: %"PRIu32"\r\n"), dev->stats.rx_expl_data);
72         printf_P(PSTR(" rx_node_id: %"PRIu32"\r\n"), dev->stats.rx_node_id);
73         printf_P(PSTR(" rx_rmt_atresp: %"PRIu32"\r\n"), dev->stats.rx_rmt_atresp);
74         printf_P(PSTR(" rx_rmt_atresp_error: %"PRIu32"\r\n"), dev->stats.rx_rmt_atresp_error);
75         printf_P(PSTR(" rx_frame_too_small: %"PRIu32"\r\n"), dev->stats.rx_frame_too_small);
76         printf_P(PSTR(" rx_frame_too_large: %"PRIu32"\r\n"), dev->stats.rx_frame_too_large);
77         printf_P(PSTR(" rx_invalid_cksum: %"PRIu32"\r\n"), dev->stats.rx_invalid_cksum);
78         printf_P(PSTR(" rx_invalid_type: %"PRIu32"\r\n"), dev->stats.rx_invalid_type);
79         printf_P(PSTR(" rx_no_delim: %"PRIu32"\r\n"), dev->stats.rx_no_delim);
80         printf_P(PSTR(" rx_usr_error: %"PRIu32"\r\n"), dev->stats.rx_usr_error);
81         printf_P(PSTR(" tx_frame: %"PRIu32"\r\n"), dev->stats.tx_frame);
82         printf_P(PSTR(" tx_atcmd: %"PRIu32"\r\n"), dev->stats.tx_atcmd);
83         printf_P(PSTR(" tx_atcmd_q: %"PRIu32"\r\n"), dev->stats.tx_atcmd_q);
84         printf_P(PSTR(" tx_data: %"PRIu32"\r\n"), dev->stats.tx_data);
85         printf_P(PSTR(" tx_expl_data: %"PRIu32"\r\n"), dev->stats.tx_expl_data);
86         printf_P(PSTR(" tx_xmit_retries: %"PRIu32"\r\n"), dev->stats.tx_xmit_retries);
87         printf_P(PSTR(" tx_rmt_atcmd: %"PRIu32"\r\n"), dev->stats.tx_rmt_atcmd);
88         printf_P(PSTR(" tx_invalid_type: %"PRIu32"\r\n"), dev->stats.tx_invalid_type);
89         printf_P(PSTR(" tx_invalid_channel: %"PRIu32"\r\n"), dev->stats.tx_invalid_channel);
90 #else
91         (void)dev;
92         printf_P(PSTR("Statistics not enabled\r\n"));
93 #endif
94 }