-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBTLE.h
More file actions
69 lines (47 loc) · 1.62 KB
/
BTLE.h
File metadata and controls
69 lines (47 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* Copyright (C) 2013 Florian Echtler <floe@butterbrot.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*/
#ifndef _BTLE_H_
#define _BTLE_H_
#include "Arduino.h"
#include <RF24.h>
// advertisement PDU
struct btle_adv_pdu {
// packet header
uint8_t pdu_type; // PDU type
uint8_t pl_size; // payload size
// MAC address
uint8_t mac[6];
// payload (including 3 bytes for CRC)
uint8_t payload[24];
};
// payload chunk in advertisement PDU payload
struct btle_pdu_chunk {
uint8_t size;
uint8_t type;
uint8_t data[];
};
// helper macro to access chunk at specific offset
#define chunk(x,y) ((btle_pdu_chunk*)(x.payload+y))
class BTLE {
public:
BTLE( RF24* _radio );
void begin( const char* _name ); // set BTLE-compatible radio parameters & name
void setChannel( uint8_t num ); // set the current channel (from 36 to 38)
void hopChannel(); // hop to the next channel
bool advertise( void* buf, uint8_t len ); // broadcast an advertisement packet with optional payload
bool listen(); // listen for advertisement packets (if true: result = buffer)
btle_adv_pdu buffer; // buffer for received BTLE packet (also used for outgoing!)
private:
void whiten( uint8_t len );
void swapbuf( uint8_t len );
void crc( uint8_t len, uint8_t* dst );
RF24* radio; // pointer to the RF24 object managing the radio
uint8_t current; // current channel index
const char* name; // name of local device
};
#endif // _BTLE_H_