COSA
An Object-Oriented Platform for Arduino Programming
Wireless.hh
Go to the documentation of this file.
1 
21 #ifndef COSA_WIRELESS_HH
22 #define COSA_WIRELESS_HH
23 
24 #include "Cosa/Types.h"
25 #include "Cosa/Power.hh"
26 
30 class Wireless {
31 public:
35  class Driver {
36  public:
40  struct addr_t {
41  uint8_t device;
42  int16_t network;
43 
50  addr_t(int16_t net, uint8_t dev)
51  {
52  network = net;
53  device = dev;
54  }
55  };
56 
58  static const uint8_t BROADCAST = 0x00;
59 
66  Driver(int16_t network, uint8_t device) :
67  m_channel(0),
68  m_addr(network, device),
69  m_avail(false),
70  m_dest(0)
71  {}
72 
77  uint8_t channel() const
78  {
79  return (m_channel);
80  }
81 
86  int16_t network_address() const
87  {
88  return (m_addr.network);
89  }
90 
95  uint8_t device_address() const
96  {
97  return (m_addr.device);
98  }
99 
106  void address(int16_t net, uint8_t dev)
107  {
108  m_addr.network = net;
109  m_addr.device = dev;
110  }
111 
117  void channel(uint8_t channel)
118  {
119  m_channel = channel;
120  }
121 
129  virtual bool begin(const void* config = NULL) = 0;
130 
137  virtual bool end()
138  {
139  return (true);
140  }
141 
146  virtual void powerup() {}
147 
152  virtual void powerdown() {}
153 
158  virtual void wakeup_on_radio() {}
159 
165  virtual bool available()
166  {
167  return (m_avail);
168  }
169 
176  virtual bool room()
177  {
178  return (true);
179  }
180 
191  virtual int send(uint8_t dest, uint8_t port, const iovec_t* vec) = 0;
192 
203  virtual int send(uint8_t dest, uint8_t port, const void* buf, size_t len)
204  {
205  iovec_t vec[2];
206  iovec_t* vp = vec;
207  iovec_arg(vp, buf, len);
208  iovec_end(vp);
209  return (send(dest, port, vec));
210  }
211 
220  virtual int broadcast(uint8_t port, const iovec_t* vec)
221  {
222  return (send(BROADCAST, port, vec));
223  }
224 
235  virtual int broadcast(uint8_t port, const void* buf, size_t len)
236  {
237  return (send(BROADCAST, port, buf, len));
238  }
239 
253  virtual int recv(uint8_t& src, uint8_t& port,
254  void* buf, size_t len,
255  uint32_t ms = 0L) = 0;
256 
262  virtual bool is_broadcast()
263  {
264  return (m_dest == BROADCAST);
265  }
266 
272  virtual void output_power_level(int8_t dBm)
273  {
274  UNUSED(dBm);
275  }
276 
282  virtual int input_power_level()
283  {
284  return (0);
285  }
286 
293  {
294  return (0);
295  }
296 
297  protected:
298  uint8_t m_channel;
300  volatile bool m_avail;
301  uint8_t m_dest;
302  };
303 };
304 #endif
uint8_t channel() const
Definition: Wireless.hh:77
virtual void output_power_level(int8_t dBm)
Definition: Wireless.hh:272
addr_t m_addr
Current network and device address.
Definition: Wireless.hh:299
#define NULL
Definition: Types.h:101
virtual int send(uint8_t dest, uint8_t port, const void *buf, size_t len)
Definition: Wireless.hh:203
virtual void powerup()
Definition: Wireless.hh:146
volatile bool m_avail
Message available. May be set by ISR.
Definition: Wireless.hh:300
uint8_t m_channel
Current channel (device dependent.
Definition: Wireless.hh:298
uint8_t m_dest
Latest message destination device address.
Definition: Wireless.hh:301
Definition: Types.h:391
void channel(uint8_t channel)
Definition: Wireless.hh:117
virtual bool begin(const void *config=NULL)=0
virtual bool available()
Definition: Wireless.hh:165
uint8_t device
Device address (LSB).
Definition: Wireless.hh:41
void address(int16_t net, uint8_t dev)
Definition: Wireless.hh:106
virtual int send(uint8_t dest, uint8_t port, const iovec_t *vec)=0
int16_t network
Network address.
Definition: Wireless.hh:42
virtual int recv(uint8_t &src, uint8_t &port, void *buf, size_t len, uint32_t ms=0L)=0
uint8_t device_address() const
Definition: Wireless.hh:95
#define UNUSED(x)
Definition: ATmega328P.hh:31
virtual int link_quality_indicator()
Definition: Wireless.hh:292
int16_t network_address() const
Definition: Wireless.hh:86
virtual int broadcast(uint8_t port, const void *buf, size_t len)
Definition: Wireless.hh:235
virtual bool is_broadcast()
Definition: Wireless.hh:262
virtual int broadcast(uint8_t port, const iovec_t *vec)
Definition: Wireless.hh:220
static const uint8_t BROADCAST
Definition: Wireless.hh:58
Driver(int16_t network, uint8_t device)
Definition: Wireless.hh:66
virtual void powerdown()
Definition: Wireless.hh:152
virtual void wakeup_on_radio()
Definition: Wireless.hh:158
addr_t(int16_t net, uint8_t dev)
Definition: Wireless.hh:50
virtual int input_power_level()
Definition: Wireless.hh:282
void iovec_arg(iovec_t *&vp, const void *buf, size_t size)
Definition: Types.h:430
void iovec_end(iovec_t *&vp)
Definition: Types.h:449
virtual bool room()
Definition: Wireless.hh:176
virtual bool end()
Definition: Wireless.hh:137