MyDriver structure renamed to MyRFDriver

The MyDriver scheme is radio specific, so it is renamed
accordingly to permit other driver schemes to coexist with it
without confusion.
This commit is contained in:
Patrick Fallberg
2015-01-28 23:53:37 +01:00
parent f1f8aec324
commit 7d37cd9aa5
12 changed files with 59 additions and 59 deletions
+4 -4
View File
@@ -19,13 +19,13 @@
#ifdef MYSENSORS_RF_NRF24
#include "MyDriverNRF24.h"
typedef class MyDriverNRF24 MyDriverClass;
#include "MyRFDriverNRF24.h"
typedef class MyRFDriverNRF24 MyRFDriverClass;
#endif
#ifdef MYSENSORS_RF_RF69
#include "MyDriverRF69.h"
typedef class MyDriverRF69 MyDriverClass;
#include "MyRFDriverRF69.h"
typedef class MyRFDriverRF69 MyRFDriverClass;
#endif
/***
-4
View File
@@ -1,4 +0,0 @@
#include "MyDriver.h"
MyDriver::MyDriver() {
}
+4
View File
@@ -0,0 +1,4 @@
#include "MyRFDriver.h"
MyRFDriver::MyRFDriver() {
}
@@ -1,5 +1,5 @@
#ifndef MyDriver_h
#define MyDriver_h
#ifndef MyRFDriver_h
#define MyRFDriver_h
#include <stdint.h>
@@ -16,13 +16,13 @@
#define GATEWAY_ADDRESS ((uint8_t)0)
#define BROADCAST_ADDRESS ((uint8_t)0xFF)
class MyDriver
class MyRFDriver
{
public:
// MyDriver constructor
// MyRFDriver constructor
// different parameters would be needed depending on radio module (e.g. pins connected etc.)
// keeping these parameters as #define's in MyConfig to streamline the driver interface
MyDriver();
MyRFDriver();
// init()
// different parameters would be needed depending on radio module (e.g. channel, power, crc, etc.)
// keeping these parameters as #define's in MyConfig to streamline the driver interface
@@ -1,11 +1,11 @@
#include "MyDriver.h"
#include "MyDriverNRF24.h"
#include "MyRFDriver.h"
#include "MyRFDriverNRF24.h"
MyDriverNRF24::MyDriverNRF24() : MyDriver() {
MyRFDriverNRF24::MyRFDriverNRF24() : MyRFDriver() {
rf24 = new RF24(RF24_CE_PIN, RF24_CS_PIN);
}
void MyDriverNRF24::init() {
void MyRFDriverNRF24::init() {
// Start up the radio library
rf24->begin();
@@ -27,18 +27,18 @@ void MyDriverNRF24::init() {
rf24->openReadingPipe(BROADCAST_PIPE, TO_ADDR(BROADCAST_ADDRESS));
}
void MyDriverNRF24::setAddress(uint8_t address) {
void MyRFDriverNRF24::setAddress(uint8_t address) {
_address = address;
rf24->openReadingPipe(WRITE_PIPE, TO_ADDR(address));
rf24->openReadingPipe(CURRENT_NODE_PIPE, TO_ADDR(address));
rf24->startListening();
}
uint8_t MyDriverNRF24::getAddress() {
uint8_t MyRFDriverNRF24::getAddress() {
return _address;
}
bool MyDriverNRF24::send(uint8_t to, const void* data, uint8_t len) {
bool MyRFDriverNRF24::send(uint8_t to, const void* data, uint8_t len) {
// Make sure radio has powered up
rf24->powerUp();
rf24->stopListening();
@@ -48,7 +48,7 @@ bool MyDriverNRF24::send(uint8_t to, const void* data, uint8_t len) {
return ok;
}
bool MyDriverNRF24::available(uint8_t *to) {
bool MyRFDriverNRF24::available(uint8_t *to) {
uint8_t pipe = 255;
boolean avail = rf24->available(&pipe);
if (pipe == CURRENT_NODE_PIPE)
@@ -58,11 +58,11 @@ bool MyDriverNRF24::available(uint8_t *to) {
return (rf24->available() && pipe < 6);
}
uint8_t MyDriverNRF24::receive(void* data) {
uint8_t MyRFDriverNRF24::receive(void* data) {
uint8_t len = rf24->getDynamicPayloadSize();
rf24->read(data, len);
}
void MyDriverNRF24::powerDown() {
void MyRFDriverNRF24::powerDown() {
rf24->powerDown();
}
@@ -1,8 +1,8 @@
#ifndef MyCommDriver_h
#define MyCommDriver_h
#ifndef MyRFDriverNRF24_h
#define MyRFDriverNRF24_h
#include "MyConfig.h"
#include "MyDriver.h"
#include "MyRFDriver.h"
#include <stdint.h>
#include "utility/RF24.h"
#include "utility/RF24_config.h"
@@ -37,10 +37,10 @@
#define CURRENT_NODE_PIPE ((uint8_t)1)
#define BROADCAST_PIPE ((uint8_t)2)
class MyDriverNRF24 : public MyDriver
class MyRFDriverNRF24 : public MyRFDriver
{
public:
MyDriverNRF24();
MyRFDriverNRF24();
void init();
void setAddress(uint8_t address);
uint8_t getAddress();
@@ -1,11 +1,11 @@
#include "MyDriver.h"
#include "MyDriverRF69.h"
#include "MyRFDriver.h"
#include "MyRFDriverRF69.h"
MyDriverRF69::MyDriverRF69() : MyDriver() {
MyRFDriverRF69::MyRFDriverRF69() : MyRFDriver() {
radio = new RFM69();
}
void MyDriverRF69::init() {
void MyRFDriverRF69::init() {
// Start up the radio library
radio->initialize(FREQUENCY,_address,NETWORKID);
#ifdef IS_RFM69HW
@@ -15,25 +15,25 @@ void MyDriverRF69::init() {
}
void MyDriverRF69::setAddress(uint8_t address) {
void MyRFDriverRF69::setAddress(uint8_t address) {
_address = address;
radio->setAddress(address);
}
uint8_t MyDriverRF69::getAddress() {
uint8_t MyRFDriverRF69::getAddress() {
return _address;
}
bool MyDriverRF69::send(uint8_t to, const void* data, uint8_t len) {
bool MyRFDriverRF69::send(uint8_t to, const void* data, uint8_t len) {
// Make sure radio has powered up
return radio->sendWithRetry(to,data,len);
}
bool MyDriverRF69::available(uint8_t *to) {
bool MyRFDriverRF69::available(uint8_t *to) {
return radio->receiveDone();
}
uint8_t MyDriverRF69::receive(void* data) {
uint8_t MyRFDriverRF69::receive(void* data) {
// for (byte i = 0; i < radio->DATALEN; i++){
// data[i]= (void)radio->DATA[i];
// }
@@ -44,6 +44,6 @@ uint8_t MyDriverRF69::receive(void* data) {
}
}
void MyDriverRF69::powerDown() {
void MyRFDriverRF69::powerDown() {
radio->sleep();
}
@@ -1,8 +1,8 @@
#ifndef MyCommDriver_h
#define MyCommDriver_h
#ifndef MyRFDriverRF69_h
#define MyRFDriverRF69_h
#include "MyConfig.h"
#include "MyDriver.h"
#include "MyRFDriver.h"
#include <stdint.h>
#include "utility/RFM69.h"
#include <SPI.h>
@@ -25,10 +25,10 @@
#define FLASH_SS 8 // and FLASH SS on D8
#endif
class MyDriverRF69 : public MyDriver
class MyRFDriverRF69 : public MyRFDriver
{
public:
MyDriverRF69();
MyRFDriverRF69();
void init();
void setAddress(uint8_t address);
uint8_t getAddress();
@@ -37,7 +37,7 @@ public:
uint8_t receive(void* data);
void powerDown();
private:
RFM69 *radio = NULL;
RFM69 *radio;
uint8_t _address;
};
+11 -11
View File
@@ -34,7 +34,7 @@ static inline bool isValidDistance( const uint8_t distance ) {
}
MySensor::MySensor() {
driver = (MyDriver*) new MyDriverClass();
radio = (MyRFDriver*) new MyRFDriverClass();
}
@@ -89,7 +89,7 @@ void MySensor::begin(void (*_msgCallback)(const MyMessage &), uint8_t _nodeId, b
}
// Open reading pipe for messages directed to this node (set write pipe to same)
driver->setAddress(nc.nodeId);
radio->setAddress(nc.nodeId);
// Send presentation for this radio node (attach
present(NODE_SENSOR_ID, repeaterMode? S_ARDUINO_REPEATER_NODE : S_ARDUINO_NODE);
@@ -105,7 +105,7 @@ void MySensor::begin(void (*_msgCallback)(const MyMessage &), uint8_t _nodeId, b
void MySensor::setupRadio() {
failedTransmissions = 0;
driver->init();
radio->init();
}
void MySensor::setupRepeaterMode(){
@@ -124,7 +124,7 @@ ControllerConfig MySensor::getConfig() {
void MySensor::requestNodeId() {
debug(PSTR("req node id\n"));
driver->setAddress(nc.nodeId);
radio->setAddress(nc.nodeId);
sendRoute(build(msg, nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_ID_REQUEST, false).set(""));
waitForReply();
}
@@ -202,7 +202,7 @@ boolean MySensor::sendWrite(uint8_t next, MyMessage &message, const bool allowFi
uint8_t length = mGetLength(message);
message.last = nc.nodeId;
mSetVersion(message, PROTOCOL_VERSION);
bool ok = driver->send(next, &message, min(MAX_MESSAGE_LENGTH, HEADER_SIZE + length));
bool ok = radio->send(next, &message, min(MAX_MESSAGE_LENGTH, HEADER_SIZE + length));
debug(PSTR("send: %d-%d-%d-%d s=%d,c=%d,t=%d,pt=%d,l=%d,st=%s:%s\n"),
message.sender,message.last, next, message.destination, message.sensor, mGetCommand(message), message.type,
@@ -264,10 +264,10 @@ void MySensor::requestTime(void (* _timeCallback)(unsigned long)) {
boolean MySensor::process() {
uint8_t to = 0;
if (!driver->available(&to))
if (!radio->available(&to))
return false;
uint8_t len = driver->receive((uint8_t *)&msg);
uint8_t len = radio->receive((uint8_t *)&msg);
// Add string termination, good if we later would want to print it.
msg.data[mGetLength(msg)] = '\0';
@@ -351,7 +351,7 @@ boolean MySensor::process() {
debug(PSTR("full\n"));
while (1); // Wait here. Nothing else we can do...
} else {
driver->setAddress(nc.nodeId);
radio->setAddress(nc.nodeId);
eeprom_write_byte((uint8_t*)EEPROM_NODE_ID_ADDRESS, nc.nodeId);
}
debug(PSTR("id=%d\n"), nc.nodeId);
@@ -482,7 +482,7 @@ void MySensor::internalSleep(unsigned long ms) {
void MySensor::sleep(unsigned long ms) {
// Let serial prints finish (debug, log etc)
Serial.flush();
driver->powerDown();
radio->powerDown();
pinIntTrigger = 0;
internalSleep(ms);
}
@@ -491,7 +491,7 @@ bool MySensor::sleep(uint8_t interrupt, uint8_t mode, unsigned long ms) {
// Let serial prints finish (debug, log etc)
bool pinTriggeredWakeup = true;
Serial.flush();
driver->powerDown();
radio->powerDown();
attachInterrupt(interrupt, wakeUp, mode);
if (ms>0) {
pinIntTrigger = 0;
@@ -510,7 +510,7 @@ bool MySensor::sleep(uint8_t interrupt, uint8_t mode, unsigned long ms) {
int8_t MySensor::sleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms) {
int8_t retVal = 1;
Serial.flush(); // Let serial prints finish (debug, log etc)
driver->powerDown();
radio->powerDown();
attachInterrupt(interrupt1, wakeUp, mode1);
attachInterrupt(interrupt2, wakeUp2, mode2);
if (ms>0) {
+2 -2
View File
@@ -13,7 +13,7 @@
#define MySensor_h
#include "Version.h" // Auto generated by bot
#include "MyDriver.h"
#include "MyRFDriver.h"
#include "MyConfig.h"
#include "MyMessage.h"
#include <stddef.h>
@@ -232,7 +232,7 @@ class MySensor
MyMessage msg; // Buffer for incoming messages.
MyMessage ack; // Buffer for ack messages.
MyDriver *driver;
MyRFDriver *radio;
void setupRepeaterMode();
void setupRadio();
@@ -1,7 +1,7 @@
#ifndef __GATEWAYUTIL_H__
#define __GATEWAYUTIL_H__
#include <MyDriver.h>
#include <MyRFDriver.h>
#ifdef ARDUINO
@@ -1,7 +1,7 @@
#ifndef __GATEWAYUTIL_H__
#define __GATEWAYUTIL_H__
#include <MyDriver.h>
#include <MyRFDriver.h>
#ifdef ARDUINO