µracoli Arduino-Support-Package Version foo

- µracoli
- User Guide
- Reference Guide

HardwareRadio.h
1 /* Copyright (c) 2013 - 2015 Daniel Thiele, Tom Magnier, Axel Wachtler
2 All rights reserved.
3
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
6 are met:
7
8 * Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 * Neither the name of the authors nor the names of its contributors
14 may be used to endorse or promote products derived from this software
15 without specific prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 POSSIBILITY OF SUCH DAMAGE. */
28
29 #ifndef HardwareRadio_h
30 #define HardwareRadio_h
31
39 #include <string.h>
40 #include "board.h"
41 #include "radio.h"
42 #include "p2p_protocol.h"
43 #include "Stream.h"
44
46 #define PHY_MIN_CHANNEL (11)
47
48 #define PHY_MAX_CHANNEL (26)
49
50 #define PHY_DEFAULT_CHANNEL (17)
51
53 #define PHY_MAX_FRAME_SIZE (127)
54
56 typedef struct radio_buffer
57 {
59 struct radio_buffer *next;
61 uint8_t len;
63 uint8_t frm[PHY_MAX_FRAME_SIZE];
65 uint8_t idx;
66 }
67 radio_buffer_t;
68
69 # if defined(__cplusplus) || defined(DOXYGEN)
70
71 class HardwareRadio : public Stream
72 {
73 private:
74 uint8_t txseq;
75 void txbuffer_init(radio_buffer_t *pbuf);
76 /* user reads from this buffer */
77 radio_buffer_t *prdbuf;
78 /* user writes to this buffer */
79 radio_buffer_t *pwrbuf;
80
81 public:
82 /* buffer which is currently transmited */
83 radio_buffer_t *txbuf;
84 /* buffer which is currently used for reception */
85 radio_buffer_t *rxbuf;
86
87 volatile uint8_t tx_in_progress;
88 node_config_t nc;
89
91 radio_buffer_t * alloc_buffer(void);
92
94 void free_buffer(radio_buffer_t * pbuf);
95
96
98 HardwareRadio(void);
99
101 void begin(void);
102
109 void begin(uint8_t channel, uint8_t idlestate);
110
112 virtual int available(void);
113
119 virtual int peek(void);
124 virtual int read(void);
129 virtual void flush(void);
130
132 virtual size_t write(uint8_t);
133
134 #if ! defined(DOXYGEN)
135 using Print::write; // pull in write(str) and write(buf, size) from Print
136 #else
137
140 void write(char * str);
141
146 void write(uint8_t *buf, uint8_t size);
147 #endif
148 };
149
150 # ifndef HARDWARERADIO_CPP
151 extern HardwareRadio Radio;
152 # endif
153 # endif
154
155 #endif /*#ifndef HardwareRadio_h*/
HardwareRadio::free_buffer
void free_buffer(radio_buffer_t *pbuf)
HardwareRadio::flush
virtual void flush(void)
HardwareRadio::available
virtual int available(void)
HardwareRadio::alloc_buffer
radio_buffer_t * alloc_buffer(void)
HardwareRadio::HardwareRadio
HardwareRadio(void)
HardwareRadio
Definition: HardwareRadio.h:71
radio_buffer_t::idx
uint8_t idx
Definition: HardwareRadio.h:65
PHY_MAX_FRAME_SIZE
#define PHY_MAX_FRAME_SIZE
Definition: HardwareRadio.h:53
radio_buffer_t::next
struct radio_buffer * next
Definition: HardwareRadio.h:59
radio_buffer_t::len
uint8_t len
Definition: HardwareRadio.h:61
HardwareRadio::begin
void begin(void)
radio_buffer_t
Definition: HardwareRadio.h:56
HardwareRadio::read
virtual int read(void)
HardwareRadio::write
virtual size_t write(uint8_t)
HardwareRadio::peek
virtual int peek(void)