RFM69 cleanup

Corrected initialization of radio
Add constructor arguments for driver
Add defaults to MyConfig
Fix ack problems reported on forum.
This commit is contained in:
Henrik Ekblad
2015-03-31 23:46:36 +02:00
parent 527b2332da
commit 6165834038
9 changed files with 116 additions and 113 deletions
+25 -4
View File
@@ -65,11 +65,14 @@
#define RF24_CS_PIN 10
#define RF24_PA_LEVEL RF24_PA_MAX
#define RF24_PA_LEVEL_GW RF24_PA_LOW
#define RF24_CHANNEL 76 //RF channel for the sensor net, 0-127
#define RF24_DATARATE RF24_250KBPS //RF24_250KBPS for 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS for 2Mbps
#define RF24_BASE_RADIO_ID ((uint64_t)0xA8A8E1FC00LL) // This is also act as base value for sensor nodeId addresses. Change this (or channel) if you have more than one sensor network.
// RF channel for the sensor net, 0-127
#define RF24_CHANNEL 76
//RF24_250KBPS for 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS for 2Mbps
#define RF24_DATARATE RF24_250KBPS
// This is also act as base value for sensor nodeId addresses. Change this (or channel) if you have more than one sensor network.
#define RF24_BASE_RADIO_ID ((uint64_t)0xA8A8E1FC00LL)
// Enable SOFTSPI for the W5100 Ethernet module
// Enable SOFTSPI for NRF24L01 when using the W5100 Ethernet module
//#define SOFTSPI
#ifdef SOFTSPI
// Define the soft SPI pins used for NRF radio
@@ -79,4 +82,22 @@
#endif
/**********************************
* RFM69 Driver Defaults
***********************************/
// Default network id. Use the same for all nodes that will talk to each other
#define RFM69_NETWORKID 100
// Default frequency to use. This must match the hardware version of the RFM69 radio (uncomment one):
// #define RFM69_FREQUENCY RF69_433MHZ
#define RFM69_FREQUENCY RF69_868MHZ
//#define FREQUENCY RF69_915MHZ
// Enable this for encryption of packets
//#define RFM69_ENABLE_ENCRYPTION
#define RFM69_ENCRYPTKEY "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes!
#endif
-57
View File
@@ -1,57 +0,0 @@
#include "MyTransport.h"
#include "MyTransportRF69.h"
MyTransportRF69::MyTransportRF69()
:
MyTransport(),
radio()
{
}
void MyTransportRF69::init() {
// Start up the radio library
radio->initialize(FREQUENCY,_address,NETWORKID);
#ifdef IS_RFM69HW
radio->setHighPower(); //uncomment only for RFM69HW!
#endif
// radio->encrypt(ENCRYPTKEY);
}
void MyTransportRF69::setAddress(uint8_t address) {
_address = address;
radio->setAddress(address);
}
uint8_t MyTransportRF69::getAddress() {
return _address;
}
bool MyTransportRF69::send(uint8_t to, const void* data, uint8_t len) {
// Make sure radio has powered up
return radio->sendWithRetry(to,data,len);
}
bool MyTransportRF69::available(uint8_t *to) {
if (radio->TARGETID == BROADCAST_ADDRESS)
*to = BROADCAST_ADDRESS;
else
*to = _address;
return radio->receiveDone();
}
uint8_t MyTransportRF69::receive(void* data) {
// for (byte i = 0; i < radio->DATALEN; i++){
// data[i]= (void)radio->DATA[i];
// }
memcpy(data,(const void *)radio->DATA, radio->DATALEN);
if (radio->ACKRequested())
{
radio->sendACK();
}
return radio->DATALEN;
}
void MyTransportRF69::powerDown() {
radio->sleep();
}
-44
View File
@@ -1,44 +0,0 @@
#ifndef MyTransportRF69_h
#define MyTransportRF69_h
#include "MyConfig.h"
#include "MyTransport.h"
#include <stdint.h>
#include "utility/RFM69.h"
#include <SPI.h>
#define NODEID 2 //unique for each node on same network
#define NETWORKID 100 //the same on all nodes that talk to each other
#define GATEWAYID 1
//Match frequency to the hardware version of the radio on your Moteino (uncomment one):
// #define FREQUENCY RF69_433MHZ
#define FREQUENCY RF69_868MHZ
//#define FREQUENCY RF69_915MHZ
#define ENCRYPTKEY "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes!
//#define IS_RFM69HW //uncomment only for RFM69HW! Leave out if you have RFM69W!
#define ACK_TIME 30 // max # of ms to wait for an ack
#ifdef __AVR_ATmega1284P__
#define LED 15 // Moteino MEGAs have LEDs on D15
#define FLASH_SS 23 // and FLASH SS on D23
#else
#define LED 9 // Moteinos have LEDs on D9
#define FLASH_SS 8 // and FLASH SS on D8
#endif
class MyTransportRF69 : public MyTransport
{
public:
MyTransportRF69();
void init();
void setAddress(uint8_t address);
uint8_t getAddress();
bool send(uint8_t to, const void* data, uint8_t len);
bool available(uint8_t *to);
uint8_t receive(void* data);
void powerDown();
private:
RFM69 *radio;
uint8_t _address;
};
#endif
+54
View File
@@ -0,0 +1,54 @@
#include "MyTransport.h"
#include "MyTransportRFM69.h"
MyTransportRFM69::MyTransportRFM69(uint8_t freqBand, uint8_t networkId, uint8_t slaveSelectPin, uint8_t interruptPin, bool isRFM69HW, uint8_t interruptNum)
:
MyTransport(),
radio(slaveSelectPin, interruptPin, isRFM69HW, interruptNum),
_freqBand(freqBand),
_networkId(networkId)
{
}
void MyTransportRFM69::init() {
// Start up the radio library (_address will be set later by the MySensors library)
radio.initialize(_freqBand, _address, _networkId);
#ifdef RFM69_ENABLE_ENCRYPTION
radio.encrypt(ENCRYPTKEY);
#endif
}
void MyTransportRFM69::setAddress(uint8_t address) {
_address = address;
radio.setAddress(address);
}
uint8_t MyTransportRFM69::getAddress() {
return _address;
}
bool MyTransportRFM69::send(uint8_t to, const void* data, uint8_t len) {
return radio.sendWithRetry(to,data,len);
}
bool MyTransportRFM69::available(uint8_t *to) {
if (radio.TARGETID == BROADCAST_ADDRESS)
*to = BROADCAST_ADDRESS;
else
*to = _address;
return radio.receiveDone();
}
uint8_t MyTransportRFM69::receive(void* data) {
memcpy(data,(const void *)radio.DATA, radio.DATALEN);
// Send ack back if this message wasn't a broadcast
if (radio.TARGETID != RF69_BROADCAST_ADDR)
radio.ACKRequested();
radio.sendACK();
return radio.DATALEN;
}
void MyTransportRFM69::powerDown() {
radio.sleep();
}
+29
View File
@@ -0,0 +1,29 @@
#ifndef MyTransportRF69_h
#define MyTransportRF69_h
#include "MyConfig.h"
#include "MyTransport.h"
#include <stdint.h>
#include "utility/RFM69.h"
#include <SPI.h>
class MyTransportRFM69 : public MyTransport
{
public:
MyTransportRFM69(uint8_t freqBand=RFM69_FREQUENCY, uint8_t networkId=RFM69_NETWORKID, uint8_t slaveSelectPin=RF69_SPI_CS, uint8_t interruptPin=RF69_IRQ_PIN, bool isRFM69HW=false, uint8_t interruptNum=RF69_IRQ_NUM);
void init();
void setAddress(uint8_t address);
uint8_t getAddress();
bool send(uint8_t to, const void* data, uint8_t len);
bool available(uint8_t *to);
uint8_t receive(void* data);
void powerDown();
private:
RFM69 radio;
uint8_t _address;
uint8_t _freqBand;
uint8_t _networkId;
};
#endif
@@ -44,7 +44,7 @@
#include <SPI.h>
#include <MySigningNone.h>
#include <MyTransportRF69.h>
#include <MyTransportRFM69.h>
#include <MyTransportNRF24.h>
#include <MyHwATMega328.h>
#include <MySigningAtsha204Soft.h>
@@ -78,7 +78,7 @@
// NRFRF24L01 radio driver (set low transmit power by default)
MyTransportNRF24 transport(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW);
//MyTransportRF69 transport;
//MyTransportRFM69 transport;
// Message signing driver (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h)
//MySigningNone signer;
@@ -60,7 +60,7 @@ http://forum.mysensors.org/topic/303/mqtt-broker-gateway
#include <SPI.h>
#include <MySigningNone.h>
#include <MyTransportRF69.h>
#include <MyTransportRFM69.h>
#include <MyTransportNRF24.h>
#include <MyHwATMega328.h>
#include <MySigningAtsha204Soft.h>
@@ -100,7 +100,7 @@ uint8_t TCP_MAC[] = { 0x02, 0xDE, 0xAD, 0x00, 0x00, 0x42 }; // Mac-address - You
// NRFRF24L01 radio driver (set low transmit power by default)
MyTransportNRF24 transport(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW);
//MyTransportRF69 transport;
//MyTransportRFM69 transport;
// Message signing driver (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h)
//MySigningNone signer;
@@ -3,7 +3,7 @@
#include <MySigningNone.h>
#include <MyTransportNRF24.h>
//#include <MyTransportRF69.h>
#include <MyTransportRFM69.h>
#include <MyHwATMega328.h>
#include <MySensor.h>
#include <SPI.h>
@@ -15,7 +15,7 @@
// NRFRF24L01 radio driver (set low transmit power by default)
MyTransportNRF24 radio(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW);
//MyTransportRF69 radio;
//MyTransportRFM69 radio;
// Message signing driver (none default)
//MySigningNone signer;
// Select AtMega328 hardware profile
@@ -24,7 +24,7 @@
#define NO_PORTB_PINCHANGES
#include <MySigningNone.h>
#include <MyTransportRF69.h>
#include <MyTransportRFM69.h>
#include <MyTransportNRF24.h>
#include <MyHwATMega328.h>
#include <MySigningAtsha204Soft.h>
@@ -46,7 +46,7 @@
// NRFRF24L01 radio driver (set low transmit power by default)
MyTransportNRF24 transport(RF24_CE_PIN, RF24_CS_PIN, RF24_PA_LEVEL_GW);
//MyTransportRF69 transport;
//MyTransportRFM69 transport;
// Message signing driver (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h)
//MySigningNone signer;