-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWSN_RFM69.h
96 lines (75 loc) · 3.51 KB
/
WSN_RFM69.h
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// **********************************************************************************
// Author: Sunit Raut github.com/SunitRaut
// **********************************************************************************
// License
// **********************************************************************************
// This program is free software; you can redistribute it
// and/or modify it under the terms of the GNU General
// Public License as published by the Free Software
// Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will
// be useful, but WITHOUT ANY WARRANTY; without even the
// implied warranty of MERCHANTABILITY or FITNESS FOR A
// PARTICULAR PURPOSE. See the GNU General Public
// License for more details.
//
// Licence can be viewed at
// http://www.gnu.org/licenses/gpl-3.0.txt
//
// Please maintain this license information along with authorship
// and copyright notices in any redistribution of this code
// **********************************************************************************
#ifndef WSN_RFM69_h
#define WSN_RFM69_h
#include <RFM69.h>
#define PSIZE 200 //Size of packet buffer in bytes. Set this according to your hardware RAM limit and your estimated RAM usage
// 200 bytes is optimal for Arduino Nano, Uno, etc with 2kB RAM. For ESP8266 or other controllers with more RAM, ou can increase the packet buffer size.
#define RETRY_TIMES 1 // How many times to retry a transmission?
#define RETRY_INTERVAL 50 // At what intervals to retry?
#define NEIGHBOUR_RETRY_LIMIT 5 // How many neighbours to try in case of failure
#define ANALOG_RANDOM_PIN A0 // Choose any analog pin to generate true random numbers.
#define MAX_BACKOFF 50 // Choose the maximum backoff period for nodes in network (in milliseconds)
class WSN_RFM69 : public RFM69
{
public:
static char pbuffer[PSIZE];
static char rbuffer[61];
static byte pwrite;
static byte pread;
static bool pflag;
static byte pLen;
static int pRSSI;
static int pSenderID;
static int backoff;
static bool sink;
static String message;
static int neighbours[10];
static byte hops_count[10]; //Array to store hop_distance of neighbouring nodes
static int neighbourCount; //Count of neighbours
static byte hops_from_sink;
static bool networkMode;
WSN_RFM69();
bool fetchPacket();
void setNetworkMode(bool flag);
void setSink(bool is_sink);
void sendToAllNeighbours();
bool sendToNeighbour(uint16_t to_node, bool requestACK);
void sendToSink();
void discoveryREQ();
bool tx_PHY(byte L1_length,int toNode,bool requestACK);
protected:
static char sendbuffer[61];
void send(uint16_t toAddress, const void* buffer, uint8_t bufferSize, bool requestACK);
bool sendWithRetry(uint16_t toAddress, const void* buffer, uint8_t bufferSize, uint8_t retries, uint8_t retryWaitTime);
static void send_ACK(const void* buffer = "", uint8_t bufferSize=0);
static void check(); //not in use (undefined)
static void isr_modif(); //not in use (undefined)
void interruptHandler();
void interruptHook(uint8_t CTLbyte);
void discoveryRESP();
void calculate_hops();
int route();
};
#endif