RF69 - reworked status codes

pull/1/head
Jan Gromeš 2018-07-23 12:42:22 +02:00
rodzic 75231e00a3
commit 0a90fc42d4
9 zmienionych plików z 265 dodań i 266 usunięć

Wyświetl plik

@ -1,8 +1,8 @@
/*
* KiteLib RF69 Receive Example
*
* This example receives packets using RF69 FSK radio module.
*/
KiteLib RF69 Receive Example
This example receives packets using RF69 FSK radio module.
*/
// include the library
#include <KiteLib.h>
@ -21,13 +21,13 @@ void setup() {
// frequency deviation: 50.0 kHz
// output power: 13 dBm
// sync word: 0x2D 0x01
byte state = rf.begin();
if(state == ERR_NONE) {
int state = rf.begin();
if (state == ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code 0x"));
Serial.println(state, HEX);
while(true);
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
}
@ -36,29 +36,29 @@ void loop() {
// you can receive data as an Arduino String
String str;
byte state = rf.receive(str);
int state = rf.receive(str);
// you can also receive data as byte array
/*
byte byteArr[8];
byte state = rf.receive(byteArr, 8);
byte byteArr[8];
int state = rf.receive(byteArr, 8);
*/
if(state == ERR_NONE) {
if (state == ERR_NONE) {
// packet was successfully received
Serial.println(F("success!"));
// print the data of the packet
Serial.print(F("[RF69] Data:\t\t"));
Serial.println(str);
} else if(state == ERR_RX_TIMEOUT) {
} else if (state == ERR_RX_TIMEOUT) {
// timeout occurred while waiting for a packet
Serial.println(F("timeout!"));
} else if(state == ERR_CRC_MISMATCH) {
} else if (state == ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("CRC error!"));
}
}

Wyświetl plik

@ -1,10 +1,10 @@
/*
* KiteLib RF69 Receive with AES Example
*
* This example receives packets using RF69 FSK radio module.
* Packets are decrypted using hardware AES.
* NOTE: When using address filtering, the address byte is NOT encrypted!
*/
KiteLib RF69 Receive with AES Example
This example receives packets using RF69 FSK radio module.
Packets are decrypted using hardware AES.
NOTE: When using address filtering, the address byte is NOT encrypted!
*/
// include the library
#include <KiteLib.h>
@ -23,19 +23,20 @@ void setup() {
// frequency deviation: 50.0 kHz
// output power: 13 dBm
// sync word: 0x2D 0x01
byte state = rf.begin();
if(state == ERR_NONE) {
int state = rf.begin();
if (state == ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code 0x"));
Serial.println(state, HEX);
while(true);
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// set AES key that will be used to decrypt the packet
// NOTE: the key must be exactly 16 bytes long!
uint8_t key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
};
rf.setAESKey(key);
// enable AES encryption
@ -43,7 +44,7 @@ void setup() {
// AES encryption can also be disabled
/*
rf.disableAES();
rf.disableAES();
*/
}
@ -52,29 +53,29 @@ void loop() {
// you can receive data as an Arduino String
String str;
byte state = rf.receive(str);
int state = rf.receive(str);
// you can also receive data as byte array
/*
byte byteArr[8];
byte state = rf.receive(byteArr, 8);
byte byteArr[8];
int state = rf.receive(byteArr, 8);
*/
if(state == ERR_NONE) {
if (state == ERR_NONE) {
// packet was successfully received
Serial.println(F("success!"));
// print the data of the packet
Serial.print(F("[RF69] Data:\t\t"));
Serial.println(str);
} else if(state == ERR_RX_TIMEOUT) {
} else if (state == ERR_RX_TIMEOUT) {
// timeout occurred while waiting for a packet
Serial.println(F("timeout!"));
} else if(state == ERR_CRC_MISMATCH) {
} else if (state == ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("CRC error!"));
}
}

Wyświetl plik

@ -1,12 +1,12 @@
/*
* KiteLib RF69 Receive with Address Example
*
* This example receives packets using RF69 FSK radio module.
* Packets can have 1-byte address of the destination node.
* After setting node (or broadcast) address, this node will
* automatically filter out any packets that do not contain
* either node address or broadcast address.
*/
KiteLib RF69 Receive with Address Example
This example receives packets using RF69 FSK radio module.
Packets can have 1-byte address of the destination node.
After setting node (or broadcast) address, this node will
automatically filter out any packets that do not contain
either node address or broadcast address.
*/
// include the library
#include <KiteLib.h>
@ -25,13 +25,13 @@ void setup() {
// frequency deviation: 50.0 kHz
// output power: 13 dBm
// sync word: 0x2D 0x01
byte state = rf.begin();
if(state == ERR_NONE) {
int state = rf.begin();
if (state == ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code 0x"));
Serial.println(state, HEX);
while(true);
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// set node address
@ -39,12 +39,12 @@ void setup() {
// address filtering (node address only)
Serial.print(F("[RF69] Setting node address ... "));
state == rf.setNodeAddress(0x02);
if(state == ERR_NONE) {
if (state == ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code 0x"));
Serial.println(state, HEX);
while(true);
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// set broadcast address
@ -52,27 +52,27 @@ void setup() {
// address filtering (node or broadcast address)
Serial.print(F("[RF69] Setting broadcast address ... "));
state == rf.setBroadcastAddress(0xFF);
if(state == ERR_NONE) {
if (state == ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code 0x"));
Serial.println(state, HEX);
while(true);
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// address filtering can also be disabled
// NOTE: calling this method will also erase previously set
// node and broadcast address
/*
Serial.print(F("[RF69] Disabling address filtering ... "));
state == rf.disableAddressFiltering();
if(state == ERR_NONE) {
Serial.print(F("[RF69] Disabling address filtering ... "));
state == rf.disableAddressFiltering();
if(state == ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code 0x"));
Serial.println(state, HEX);
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
}
*/
}
@ -81,15 +81,15 @@ void loop() {
// you can receive data as an Arduino String
String str;
byte state = rf.receive(str);
int state = rf.receive(str);
// you can also receive data as byte array
/*
byte byteArr[8];
byte state = rf.receive(byteArr, 8);
byte byteArr[8];
int state = rf.receive(byteArr, 8);
*/
if(state == ERR_NONE) {
if (state == ERR_NONE) {
// packet was successfully received
Serial.println(F("success!"));
@ -97,21 +97,21 @@ void loop() {
Serial.print(F("[RF69] Data:\t\t"));
Serial.println(str);
/*
for(int i = 0; i < 8; i++) {
for(int i = 0; i < 8; i++) {
Serial.print("0x");
Serial.print(byteArr[i], HEX);
Serial.print(' ');
}
Serial.println();
}
Serial.println();
*/
} else if(state == ERR_RX_TIMEOUT) {
} else if (state == ERR_RX_TIMEOUT) {
// timeout occurred while waiting for a packet
Serial.println(F("timeout!"));
} else if(state == ERR_CRC_MISMATCH) {
} else if (state == ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("CRC error!"));
}
}

Wyświetl plik

@ -1,16 +1,16 @@
/*
* KiteLib SX127x Settings Example
*
* This example shows how to change all the properties of RF69 radio.
* KiteLib currently supports the following settings:
* - pins (SPI slave select, digital IO 0, digital IO 1)
* - carrier frequency
* - bit rate
* - receiver bandwidth
* - allowed frequency deviation
* - output power during transmission
* - sync word
*/
KiteLib SX127x Settings Example
This example shows how to change all the properties of RF69 radio.
KiteLib currently supports the following settings:
- pins (SPI slave select, digital IO 0, digital IO 1)
- carrier frequency
- bit rate
- receiver bandwidth
- allowed frequency deviation
- output power during transmission
- sync word
*/
// include the library
#include <KiteLib.h>
@ -27,7 +27,7 @@ RF69 rf2 = new Module(6, 4, 5);
void setup() {
Serial.begin(9600);
// initialize RF69 with default settings
Serial.print(F("[RF69] Initializing ... "));
// carrier frequency: 434.0 MHz
@ -36,13 +36,13 @@ void setup() {
// frequency deviation: 50.0 kHz
// output power: 13 dBm
// sync word: 0x2D 0x01
byte state = rf1.begin();
if(state == ERR_NONE) {
int state = rf1.begin();
if (state == ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code 0x"));
Serial.println(state, HEX);
while(true);
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// initialize RF69 with non-default settings
@ -54,64 +54,64 @@ void setup() {
// output power: 17 dBm
// sync word: 0x2D 0x01
state = rf1.begin(868.0, 300.0, 250.0, 60.0, 17);
if(state == ERR_NONE) {
if (state == ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code 0x"));
Serial.println(state, HEX);
while(true);
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// you can also change the settings at runtime
// and check if the configuration was changed successfully
// set carrier frequency to 433.5 MHz
if(rf1.setFrequency(433.5) == ERR_INVALID_FREQUENCY) {
if (rf1.setFrequency(433.5) == ERR_INVALID_FREQUENCY) {
Serial.println(F("Selected frequency is invalid for this module!"));
while(true);
while (true);
}
// set bit rate to 100.0 kbps
state = rf1.setBitRate(100.0);
if(state == ERR_INVALID_BIT_RATE) {
if (state == ERR_INVALID_BIT_RATE) {
Serial.println(F("[RF69] Selected bit rate is invalid for this module!"));
while(true);
} else if(state == ERR_INVALID_BIT_RATE_BW_RATIO) {
while (true);
} else if (state == ERR_INVALID_BIT_RATE_BW_RATIO) {
Serial.println(F("[RF69] Selected bit rate to bandwidth ratio is invalid!"));
Serial.println(F("[RF69] Increase receiver bandwidth to set this bit rate."));
while(true);
while (true);
}
// set receiver bandwidth to 250.0 kHz
state = rf1.setRxBandwidth(250.0);
if(state == ERR_INVALID_RX_BANDWIDTH) {
if (state == ERR_INVALID_RX_BANDWIDTH) {
Serial.println(F("[RF69] Selected receiver bandwidth is invalid for this module!"));
while(true);
} else if(state == ERR_INVALID_BIT_RATE_BW_RATIO) {
while (true);
} else if (state == ERR_INVALID_BIT_RATE_BW_RATIO) {
Serial.println(F("[RF69] Selected bit rate to bandwidth ratio is invalid!"));
Serial.println(F("[RF69] Decrease bit rate to set this receiver bandwidth."));
while(true);
while (true);
}
// set allowed frequency deviation to 10.0 kHz
if(rf1.setFrequencyDeviation(10.0) == ERR_INVALID_FREQUENCY_DEVIATION) {
if (rf1.setFrequencyDeviation(10.0) == ERR_INVALID_FREQUENCY_DEVIATION) {
Serial.println(F("[RF69] Selected frequency deviation is invalid for this module!"));
while(true);
while (true);
}
// set output power to 2 dBm
if(rf1.setOutputPower(2) == ERR_INVALID_OUTPUT_POWER) {
if (rf1.setOutputPower(2) == ERR_INVALID_OUTPUT_POWER) {
Serial.println(F("[RF69] Selected output power is invalid for this module!"));
while(true);
while (true);
}
// up to 8 bytes can be set as sync word
// NOTE: sync word must not conatin any zero bytes
// set sync word to 0x01 0x23 0x45 0x67 0x89 0xAB 0xCD 0xEF
uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF};
if(rf1.setSyncWord(syncWord, 8) == ERR_INVALID_SYNC_WORD) {
if (rf1.setSyncWord(syncWord, 8) == ERR_INVALID_SYNC_WORD) {
Serial.println(F("[RF69] Selected sync word is invalid for this module!"));
while(true);
while (true);
}
Serial.println(F("[RF69] All settings changed successfully!"));
@ -119,7 +119,7 @@ void setup() {
// RF69 can also measure temperature (roughly)
// to get correct temperature measurements, the sensor must be calibrated
// at ambient temperature
rf1.setAmbientTemperature(25); // replace 25 with your ambient temperature
rf1.setAmbientTemperature(25); // replace 25 with your ambient temperature
}
void loop() {

Wyświetl plik

@ -1,8 +1,8 @@
/*
* KiteLib RF69 Transmit Example
*
* This example transmits packets using RF69 FSK radio module.
*/
KiteLib RF69 Transmit Example
This example transmits packets using RF69 FSK radio module.
*/
// include the library
#include <KiteLib.h>
@ -21,13 +21,13 @@ void setup() {
// frequency deviation: 50.0 kHz
// output power: 13 dBm
// sync word: 0x2D 0x01
byte state = rf.begin();
if(state == ERR_NONE) {
int state = rf.begin();
if (state == ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code 0x"));
Serial.println(state, HEX);
while(true);
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
}
@ -35,22 +35,22 @@ void loop() {
Serial.print(F("[RF69] Transmitting packet ... "));
// you can transmit C-string or Arduino string up to 64 characters long
byte state = rf.transmit("Hello World!");
int state = rf.transmit("Hello World!");
// you can also transmit byte array up to 64 bytes long
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF};
byte state = rf.transmit(byteArr, 8);
byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF};
int state = rf.transmit(byteArr, 8);
*/
if(state == ERR_NONE) {
if (state == ERR_NONE) {
// the packet was successfully transmitted
Serial.println(" success!");
} else if(state == ERR_PACKET_TOO_LONG) {
// the supplied packet was longer than 256 bytes
} else if (state == ERR_PACKET_TOO_LONG) {
// the supplied packet was longer than 64 bytes
Serial.println(" too long!");
}
// wait for a second before transmitting again

Wyświetl plik

@ -1,10 +1,10 @@
/*
* KiteLib RF69 Transmit with AES Example
*
* This example transmits packets using RF69 FSK radio module.
* Packets are encrypted using hardware AES.
* NOTE: When using address filtering, the address byte is NOT encrypted!
*/
KiteLib RF69 Transmit with AES Example
This example transmits packets using RF69 FSK radio module.
Packets are encrypted using hardware AES.
NOTE: When using address filtering, the address byte is NOT encrypted!
*/
// include the library
#include <KiteLib.h>
@ -23,19 +23,20 @@ void setup() {
// frequency deviation: 50.0 kHz
// output power: 13 dBm
// sync word: 0x2D 0x01
byte state = rf.begin();
if(state == ERR_NONE) {
int state = rf.begin();
if (state == ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code 0x"));
Serial.println(state, HEX);
while(true);
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// set AES key to encrypt the packet
// NOTE: the key must be exactly 16 bytes long!
uint8_t key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
};
rf.setAESKey(key);
// enable AES encryption
@ -43,7 +44,7 @@ void setup() {
// AES encryption can also be disabled
/*
rf.disableAES();
rf.disableAES();
*/
}
@ -51,22 +52,22 @@ void loop() {
Serial.print(F("[RF69] Transmitting packet ... "));
// you can transmit C-string or Arduino string up to 64 characters long
byte state = rf.transmit("Hello World!");
int state = rf.transmit("Hello World!");
// you can also transmit byte array up to 64 bytes long
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF};
byte state = rf.transmit(byteArr, 8);
byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF};
int state = rf.transmit(byteArr, 8);
*/
if(state == ERR_NONE) {
if (state == ERR_NONE) {
// the packet was successfully transmitted
Serial.println(" success!");
} else if(state == ERR_PACKET_TOO_LONG) {
} else if (state == ERR_PACKET_TOO_LONG) {
// the supplied packet was longer than 256 bytes
Serial.println(" too long!");
}
// wait for a second before transmitting again

Wyświetl plik

@ -1,12 +1,12 @@
/*
* KiteLib RF69 Transmit to Address Example
*
* This example transmits packets using RF69 FSK radio module.
* Packets can have 1-byte address of the destination node.
* After setting node (or broadcast) address, this node will
* automatically filter out any packets that do not contain
* either node address or broadcast address.
*/
KiteLib RF69 Transmit to Address Example
This example transmits packets using RF69 FSK radio module.
Packets can have 1-byte address of the destination node.
After setting node (or broadcast) address, this node will
automatically filter out any packets that do not contain
either node address or broadcast address.
*/
// include the library
#include <KiteLib.h>
@ -25,13 +25,13 @@ void setup() {
// frequency deviation: 50.0 kHz
// output power: 13 dBm
// sync word: 0x2D 0x01
byte state = rf.begin();
if(state == ERR_NONE) {
int state = rf.begin();
if (state == ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code 0x"));
Serial.println(state, HEX);
while(true);
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// set node address
@ -39,12 +39,12 @@ void setup() {
// address filtering (node address only)
Serial.print(F("[RF69] Setting node address ... "));
state == rf.setNodeAddress(0x01);
if(state == ERR_NONE) {
if (state == ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code 0x"));
Serial.println(state, HEX);
while(true);
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// set broadcast address
@ -52,27 +52,27 @@ void setup() {
// address filtering (node or broadcast address)
Serial.print(F("[RF69] Setting broadcast address ... "));
state == rf.setBroadcastAddress(0xFF);
if(state == ERR_NONE) {
if (state == ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code 0x"));
Serial.println(state, HEX);
while(true);
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// address filtering can also be disabled
// NOTE: calling this method will also erase previously set
// node and broadcast address
/*
Serial.print(F("[RF69] Disabling address filtering ... "));
state == rf.disableAddressFiltering();
if(state == ERR_NONE) {
Serial.print(F("[RF69] Disabling address filtering ... "));
state == rf.disableAddressFiltering();
if(state == ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code 0x"));
Serial.println(state, HEX);
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
}
*/
}
@ -80,33 +80,33 @@ void loop() {
Serial.print(F("[RF69] Transmitting packet ... "));
// transmit C-string or Arduino string to node with address 0x02
//byte state = rf.transmit("Hello World!", 0x02);
//int state = rf.transmit("Hello World!", 0x02);
// transmit byte array to node with address 0x02
byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF};
byte state = rf.transmit(byteArr, 8, 0x02);
int state = rf.transmit(byteArr, 8, 0x02);
// transmit C-string or Arduino string in broadcast mode
/*
byte state = rf.transmit("Hello World!", 0xFF);
int state = rf.transmit("Hello World!", 0xFF);
*/
// transmit byte array in broadcast mode
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x56, 0x78, 0xAB, 0xCD, 0xEF};
byte state = rf.transmit(byteArr, 8, 0xFF);
byte byteArr[] = {0x01, 0x23, 0x45, 0x56, 0x78, 0xAB, 0xCD, 0xEF};
int state = rf.transmit(byteArr, 8, 0xFF);
*/
if(state == ERR_NONE) {
if (state == ERR_NONE) {
// the packet was successfully transmitted
Serial.println(" success!");
} else if(state == ERR_PACKET_TOO_LONG) {
} else if (state == ERR_PACKET_TOO_LONG) {
// the supplied packet was longer than 256 bytes
Serial.println(" too long!");
}
// wait for a second before transmitting again

Wyświetl plik

@ -5,7 +5,7 @@ RF69::RF69(Module* module) {
_tempOffset = 0;
}
uint8_t RF69::begin(float freq, float br, float rxBw, float freqDev, int8_t power) {
int16_t RF69::begin(float freq, float br, float rxBw, float freqDev, int8_t power) {
// set module properties
_mod->init(USE_SPI, INT_0);
@ -18,13 +18,14 @@ uint8_t RF69::begin(float freq, float br, float rxBw, float freqDev, int8_t powe
flagFound = true;
} else {
#ifdef KITELIB_DEBUG
Serial.print("RF69 not found! (");
Serial.print(F("RF69 not found! ("));
Serial.print(i + 1);
Serial.print(" of 10 tries) RF69_REG_VERSION == ");
Serial.print(F(" of 10 tries) RF69_REG_VERSION == "));
char buffHex[5];
sprintf(buffHex, "0x%02X", version);
char buffHex[7];
sprintf(buffHex, "0x%04X", version);
Serial.print(buffHex);
Serial.print(F(", expected 0x0024"));
Serial.println();
#endif
delay(1000);
@ -41,7 +42,7 @@ uint8_t RF69::begin(float freq, float br, float rxBw, float freqDev, int8_t powe
}
// configure settings not accessible by API
uint8_t state = config();
int16_t state = config();
if(state != ERR_NONE) {
return(state);
}
@ -83,7 +84,7 @@ uint8_t RF69::begin(float freq, float br, float rxBw, float freqDev, int8_t powe
return(ERR_NONE);
}
uint8_t RF69::transmit(uint8_t* data, size_t len, uint8_t addr) {
int16_t RF69::transmit(uint8_t* data, size_t len, uint8_t addr) {
// check packet length
if(len > 64) {
return(ERR_PACKET_TOO_LONG);
@ -124,15 +125,15 @@ uint8_t RF69::transmit(uint8_t* data, size_t len, uint8_t addr) {
return(ERR_NONE);
}
uint8_t RF69::transmit(const char* str, uint8_t addr) {
int16_t RF69::transmit(const char* str, uint8_t addr) {
return(RF69::transmit((uint8_t*)str, strlen(str), addr));
}
uint8_t RF69::transmit(String& str, uint8_t addr) {
int16_t RF69::transmit(String& str, uint8_t addr) {
return(RF69::transmit(str.c_str()));
}
uint8_t RF69::receive(uint8_t* data, size_t len) {
int16_t RF69::receive(uint8_t* data, size_t len) {
// set mode to standby
setMode(RF69_STANDBY);
@ -184,10 +185,10 @@ uint8_t RF69::receive(uint8_t* data, size_t len) {
return(ERR_NONE);
}
uint8_t RF69::receive(String& str, size_t len) {
int16_t RF69::receive(String& str, size_t len) {
// create temporary array to store received data
char* data = new char[len];
uint8_t state = RF69::receive((uint8_t*)data, len);
int16_t state = RF69::receive((uint8_t*)data, len);
// if packet was received successfully, copy data into String
if(state == ERR_NONE) {
@ -198,12 +199,12 @@ uint8_t RF69::receive(String& str, size_t len) {
return(state);
}
uint8_t RF69::sleep() {
int16_t RF69::sleep() {
// set module to sleep
return(setMode(RF69_SLEEP));
}
uint8_t RF69::standby() {
int16_t RF69::standby() {
// set module to standby
return(setMode(RF69_STANDBY));
}
@ -212,15 +213,15 @@ void RF69::setAESKey(uint8_t* key) {
_mod->SPIwriteRegisterBurst(RF69_REG_AES_KEY_1, key, 16);
}
uint8_t RF69::enableAES() {
int16_t RF69::enableAES() {
return(_mod->SPIsetRegValue(RF69_REG_PACKET_CONFIG_2, RF69_AES_ON, 0, 0));
}
uint8_t RF69::disableAES() {
int16_t RF69::disableAES() {
return(_mod->SPIsetRegValue(RF69_REG_PACKET_CONFIG_2, RF69_AES_OFF, 0, 0));
}
uint8_t RF69::setFrequency(float freq) {
int16_t RF69::setFrequency(float freq) {
// check allowed frequency range
if(!((freq > 290.0) && (freq < 340.0) ||
(freq > 431.0) && (freq < 510.0) ||
@ -234,14 +235,14 @@ uint8_t RF69::setFrequency(float freq) {
//set carrier frequency
uint32_t base = 1;
uint32_t FRF = (freq * (base << 19)) / 32.0;
uint8_t state = _mod->SPIsetRegValue(RF69_REG_FRF_MSB, (FRF & 0xFF0000) >> 16, 7, 0);
int16_t state = _mod->SPIsetRegValue(RF69_REG_FRF_MSB, (FRF & 0xFF0000) >> 16, 7, 0);
state |= _mod->SPIsetRegValue(RF69_REG_FRF_MID, (FRF & 0x00FF00) >> 8, 7, 0);
state |= _mod->SPIsetRegValue(RF69_REG_FRF_LSB, FRF & 0x0000FF, 7, 0);
return(state);
}
uint8_t RF69::setBitRate(float br) {
int16_t RF69::setBitRate(float br) {
// check allowed bitrate
if((br < 1.2) || (br > 300.0)) {
return(ERR_INVALID_BIT_RATE);
@ -257,7 +258,7 @@ uint8_t RF69::setBitRate(float br) {
// set bit rate
uint16_t bitRate = 32000 / br;
uint8_t state = _mod->SPIsetRegValue(RF69_REG_BITRATE_MSB, (bitRate & 0xFF00) >> 8, 7, 0);
int16_t state = _mod->SPIsetRegValue(RF69_REG_BITRATE_MSB, (bitRate & 0xFF00) >> 8, 7, 0);
state |= _mod->SPIsetRegValue(RF69_REG_BITRATE_LSB, bitRate & 0x00FF, 7, 0);
if(state == ERR_NONE) {
RF69::_br = br;
@ -265,7 +266,7 @@ uint8_t RF69::setBitRate(float br) {
return(state);
}
uint8_t RF69::setRxBandwidth(float rxBw) {
int16_t RF69::setRxBandwidth(float rxBw) {
// check bitrate-bandwidth ratio
if(!(_br < 2000 * rxBw)) {
return(ERR_INVALID_BIT_RATE_BW_RATIO);
@ -353,14 +354,14 @@ uint8_t RF69::setRxBandwidth(float rxBw) {
setMode(RF69_STANDBY);
// set Rx bandwidth
uint8_t state = _mod->SPIsetRegValue(RF69_REG_RX_BW, RF69_DCC_FREQ | bwMant | bwExp, 7, 0);
int16_t state = _mod->SPIsetRegValue(RF69_REG_RX_BW, RF69_DCC_FREQ | bwMant | bwExp, 7, 0);
if(state == ERR_NONE) {
RF69::_rxBw = rxBw;
}
return(state);
}
uint8_t RF69::setFrequencyDeviation(float freqDev) {
int16_t RF69::setFrequencyDeviation(float freqDev) {
// check frequency deviation range
if(!((freqDev + _br/2 <= 500) && (freqDev >= 0.6))) {
return(ERR_INVALID_FREQUENCY_DEVIATION);
@ -372,13 +373,13 @@ uint8_t RF69::setFrequencyDeviation(float freqDev) {
// set allowed frequency deviation
uint32_t base = 1;
uint32_t FDEV = (freqDev * (base << 19)) / 32000;
uint8_t state = _mod->SPIsetRegValue(RF69_REG_FDEV_MSB, (FDEV & 0xFF00) >> 8, 5, 0);
int16_t state = _mod->SPIsetRegValue(RF69_REG_FDEV_MSB, (FDEV & 0xFF00) >> 8, 5, 0);
state |= _mod->SPIsetRegValue(RF69_REG_FDEV_LSB, FDEV & 0x00FF, 7, 0);
return(state);
}
uint8_t RF69::setOutputPower(int8_t power) {
int16_t RF69::setOutputPower(int8_t power) {
// check output power range
if((power < -18) || (power > 17)) {
return(ERR_INVALID_OUTPUT_POWER);
@ -388,7 +389,7 @@ uint8_t RF69::setOutputPower(int8_t power) {
setMode(RF69_STANDBY);
// set output power
uint8_t state;
int16_t state;
if(power > 13) {
// requested output power is higher than 13 dBm, enable PA2 + PA1 on PA_BOOST
state = _mod->SPIsetRegValue(RF69_REG_PA_LEVEL, RF69_PA0_OFF | RF69_PA1_ON | RF69_PA2_ON | power + 14, 7, 0);
@ -400,7 +401,7 @@ uint8_t RF69::setOutputPower(int8_t power) {
return(state);
}
uint8_t RF69::setSyncWord(uint8_t* syncWord, size_t len, uint8_t maxErrBits) {
int16_t RF69::setSyncWord(uint8_t* syncWord, size_t len, uint8_t maxErrBits) {
// check constraints
if((maxErrBits > 7) || (len > 8)) {
return(ERR_INVALID_SYNC_WORD);
@ -414,7 +415,7 @@ uint8_t RF69::setSyncWord(uint8_t* syncWord, size_t len, uint8_t maxErrBits) {
}
// enable sync word recognition
uint8_t state = _mod->SPIsetRegValue(RF69_REG_SYNC_CONFIG, RF69_SYNC_ON | RF69_FIFO_FILL_CONDITION_SYNC | (len - 1) << 3 | maxErrBits, 7, 0);
int16_t state = _mod->SPIsetRegValue(RF69_REG_SYNC_CONFIG, RF69_SYNC_ON | RF69_FIFO_FILL_CONDITION_SYNC | (len - 1) << 3 | maxErrBits, 7, 0);
if(state != ERR_NONE) {
return(state);
}
@ -424,9 +425,9 @@ uint8_t RF69::setSyncWord(uint8_t* syncWord, size_t len, uint8_t maxErrBits) {
return(ERR_NONE);
}
uint8_t RF69::setNodeAddress(uint8_t nodeAddr) {
int16_t RF69::setNodeAddress(uint8_t nodeAddr) {
// enable address filtering (node only)
uint8_t state = _mod->SPIsetRegValue(RF69_REG_PACKET_CONFIG_1, RF69_ADDRESS_FILTERING_NODE, 2, 1);
int16_t state = _mod->SPIsetRegValue(RF69_REG_PACKET_CONFIG_1, RF69_ADDRESS_FILTERING_NODE, 2, 1);
if(state != ERR_NONE) {
return(state);
}
@ -435,9 +436,9 @@ uint8_t RF69::setNodeAddress(uint8_t nodeAddr) {
return(_mod->SPIsetRegValue(RF69_REG_NODE_ADRS, nodeAddr));
}
uint8_t RF69::setBroadcastAddress(uint8_t broadAddr) {
int16_t RF69::setBroadcastAddress(uint8_t broadAddr) {
// enable address filtering (node + broadcast)
uint8_t state = _mod->SPIsetRegValue(RF69_REG_PACKET_CONFIG_1, RF69_ADDRESS_FILTERING_NODE_BROADCAST, 2, 1);
int16_t state = _mod->SPIsetRegValue(RF69_REG_PACKET_CONFIG_1, RF69_ADDRESS_FILTERING_NODE_BROADCAST, 2, 1);
if(state != ERR_NONE) {
return(state);
}
@ -446,9 +447,9 @@ uint8_t RF69::setBroadcastAddress(uint8_t broadAddr) {
return(_mod->SPIsetRegValue(RF69_REG_BROADCAST_ADRS, broadAddr));
}
uint8_t RF69::disableAddressFiltering() {
int16_t RF69::disableAddressFiltering() {
// disable address filtering
uint8_t state = _mod->SPIsetRegValue(RF69_REG_PACKET_CONFIG_1, RF69_ADDRESS_FILTERING_OFF, 2, 1);
int16_t state = _mod->SPIsetRegValue(RF69_REG_PACKET_CONFIG_1, RF69_ADDRESS_FILTERING_OFF, 2, 1);
if(state != ERR_NONE) {
return(state);
}
@ -484,8 +485,8 @@ int16_t RF69::getTemperature() {
return(0 - (rawTemp + _tempOffset));
}
uint8_t RF69::config() {
uint8_t state = ERR_NONE;
int16_t RF69::config() {
int16_t state = ERR_NONE;
// set mode to STANDBY
state = setMode(RF69_STANDBY);
@ -518,11 +519,8 @@ uint8_t RF69::config() {
return(state);
}
// reset FIFO flags
state = _mod->SPIsetRegValue(RF69_REG_IRQ_FLAGS_2, RF69_IRQ_FIFO_OVERRUN, 4, 4);
if(state != ERR_NONE) {
return(state);
}
// reset FIFO flag
_mod->SPIwriteRegister(RF69_REG_IRQ_FLAGS_2, RF69_IRQ_FIFO_OVERRUN);
// disable ClkOut on DIO5
state = _mod->SPIsetRegValue(RF69_REG_DIO_MAPPING_2, RF69_CLK_OUT_OFF, 2, 0);
@ -566,9 +564,8 @@ uint8_t RF69::config() {
return(ERR_NONE);
}
uint8_t RF69::setMode(uint8_t mode) {
_mod->SPIsetRegValue(RF69_REG_OP_MODE, mode, 4, 2);
return(ERR_NONE);
int16_t RF69::setMode(uint8_t mode) {
return(_mod->SPIsetRegValue(RF69_REG_OP_MODE, mode, 4, 2));
}
void RF69::clearIRQFlags() {

Wyświetl plik

@ -418,30 +418,30 @@ class RF69 {
RF69(Module* module);
// basic methods
uint8_t begin(float freq = 434.0, float br = 48.0, float rxBw = 125.0, float freqDev = 50.0, int8_t power = 13);
uint8_t transmit(uint8_t* data, size_t len, uint8_t addr = 0);
uint8_t transmit(const char* str, uint8_t addr = 0);
uint8_t transmit(String& str, uint8_t addr = 0);
uint8_t receive(uint8_t* data, size_t len);
uint8_t receive(String& str, size_t len = 0);
uint8_t sleep();
uint8_t standby();
int16_t begin(float freq = 434.0, float br = 48.0, float rxBw = 125.0, float freqDev = 50.0, int8_t power = 13);
int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0);
int16_t transmit(const char* str, uint8_t addr = 0);
int16_t transmit(String& str, uint8_t addr = 0);
int16_t receive(uint8_t* data, size_t len);
int16_t receive(String& str, size_t len = 0);
int16_t sleep();
int16_t standby();
// hardware AES support
void setAESKey(uint8_t* key);
uint8_t enableAES();
uint8_t disableAES();
int16_t enableAES();
int16_t disableAES();
// configuration methods
uint8_t setFrequency(float freq);
uint8_t setBitRate(float br);
uint8_t setRxBandwidth(float rxBw);
uint8_t setFrequencyDeviation(float freqDev);
uint8_t setOutputPower(int8_t power);
uint8_t setSyncWord(uint8_t* syncWord, size_t len, uint8_t maxErrBits = 0);
uint8_t setNodeAddress(uint8_t nodeAddr);
uint8_t setBroadcastAddress(uint8_t broadAddr);
uint8_t disableAddressFiltering();
int16_t setFrequency(float freq);
int16_t setBitRate(float br);
int16_t setRxBandwidth(float rxBw);
int16_t setFrequencyDeviation(float freqDev);
int16_t setOutputPower(int8_t power);
int16_t setSyncWord(uint8_t* syncWord, size_t len, uint8_t maxErrBits = 0);
int16_t setNodeAddress(uint8_t nodeAddr);
int16_t setBroadcastAddress(uint8_t broadAddr);
int16_t disableAddressFiltering();
// measurement methods
void setAmbientTemperature(int16_t tempAmbient);
@ -454,10 +454,10 @@ class RF69 {
float _rxBw;
int16_t _tempOffset;
uint8_t config();
int16_t config();
private:
uint8_t setMode(uint8_t mode);
int16_t setMode(uint8_t mode);
void clearIRQFlags();
};