EthernetGateway added. Removed usage of string class i Gateway code (reduced program memroy by 2k). FIxed potential problem in Dallas sensor example sketch.

This commit is contained in:
Henrik Ekblad
2014-02-07 22:44:13 +01:00
parent 1ae8353d13
commit 94f800c18b
95 changed files with 20969 additions and 31 deletions
+14 -4
View File
@@ -27,8 +27,15 @@ Gateway::Gateway(uint8_t _cepin, uint8_t _cspin, uint8_t _inclusion, uint8_t _in
pinEr = _er;
}
void Gateway::begin(uint8_t _radioId, void (*inDataCallback)(char *)) {
if (inDataCallback != NULL) {
useWriteCallback = true;
dataCallback = inDataCallback;
} else {
useWriteCallback = false;
}
void Gateway::begin(uint8_t _radioId) {
radioId = 0;
distance = 0;
inclusionMode = 0;
@@ -103,7 +110,7 @@ void Gateway::checkInclusionFinished() {
}
void Gateway::parseAndSend(String inputString) {
void Gateway::parseAndSend(char *commandBuffer) {
boolean ok;
char *str, *p, *value;
int i = 0;
@@ -111,8 +118,6 @@ void Gateway::parseAndSend(String inputString) {
uint8_t childId;
uint8_t messageType;
uint8_t type;
// Copy command to char* buffer
inputString.toCharArray(commandBuffer, MAX_RECEIVE_LENGTH);
// Extract command data coming on serial line
for (str = strtok_r(commandBuffer, ";", &p); // split using semicolon
@@ -150,6 +155,7 @@ void Gateway::parseAndSend(String inputString) {
}
} else {
txBlink(1);
ok = sendData(GATEWAY_ADDRESS, sensorRadioId, childId, messageType, type, value, strlen(value), false);
if (!ok) {
errBlink(1);
@@ -202,6 +208,10 @@ void Gateway::serial(const char *fmt, ... ) {
vsnprintf_P(serialBuffer, MAX_SEND_LENGTH, fmt, args);
va_end (args);
Serial.print(serialBuffer);
if (useWriteCallback) {
// We have a registered write callback (probably Ethernet)
dataCallback(serialBuffer);
}
}
void Gateway::serial(message_s msg) {
+9 -8
View File
@@ -14,11 +14,9 @@
#include "Relay.h"
#define MAX_RECEIVE_LENGTH 50 // Max buffersize needed for messages coming from vera
#define MAX_RECEIVE_LENGTH 100 // Max buffersize needed for messages coming from vera
#define MAX_SEND_LENGTH 120 // Max buffersize needed for messages coming from vera
class Gateway : public Relay
{
public:
@@ -41,17 +39,16 @@ class Gateway : public Relay
Gateway(uint8_t _cepin, uint8_t _cspin, uint8_t _inclusion_time);
Gateway(uint8_t _cepin, uint8_t _cspin, uint8_t _inclusion, uint8_t _inclusion_time, uint8_t _rx, uint8_t _tx, uint8_t _er);
void begin(uint8_t _radioId = 0);
/* Use this and pass a function that should be called when you want to process commands that arrive from radio network */
void begin(uint8_t _radioId=AUTO, void (*dataCallback)(char *)=NULL);
void processRadioMessage();
void parseAndSend(String inputString);
void parseAndSend(char *inputString);
boolean isLedMode();
void ledTimersInterrupt();
void startInclusionInterrupt();
private:
char commandBuffer[MAX_RECEIVE_LENGTH];
char serialBuffer[MAX_SEND_LENGTH]; // Buffer for building string when sending data to vera
unsigned long inclusionStartTime;
boolean inclusionMode; // Keeps track on inclusion mode
@@ -60,6 +57,10 @@ class Gateway : public Relay
volatile uint8_t countTx;
volatile uint8_t countErr;
boolean ledMode;
boolean useWriteCallback;
void (*dataCallback)(char *);
uint8_t pinInclusion;
uint8_t inclusionTime;
uint8_t pinRx;
+1 -1
View File
@@ -39,7 +39,7 @@ class Relay : public Sensor
*/
Relay(uint8_t _cepin, uint8_t _cspin);
void begin(uint8_t _radioId);
void begin(uint8_t _radioId=AUTO);
boolean messageAvailable();
boolean send(message_s message, int length);
+2 -3
View File
@@ -22,7 +22,7 @@
#include <avr/progmem.h>
#include <stdarg.h>
#define DEBUG
//#define DEBUG
#ifdef DEBUG
#define debug(x,...) debugPrint(x, ##__VA_ARGS__)
@@ -134,8 +134,7 @@ class Sensor : public RF24
* Call this in setup(), before calling any other sensor net library methods.
* @param _radioId The unique id (1-254) for this sensor. Specify 255 for auto id mode.
*/
void begin(uint8_t _radioId);
void begin(uint8_t _radioId=AUTO);
uint8_t getRadioId();
@@ -35,7 +35,7 @@ void setup()
// Fetch the number of attached sensors
numSensors = sensors.getDeviceCount();
// Register all sensors to gw (they will be created as child devices)
for (int i=0; i<numSensors; i++) {
for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
gw.sendSensorPresentation(i, S_TEMP);
}
metric = gw.isMetricSystem();
@@ -48,7 +48,7 @@ void loop()
{
sensors.requestTemperatures(); // Fetch temperatures from Dallas
delay(100);
for (int i=0; i<numSensors; i++) {
for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
// Fetch and round temperature to one decimal
float temperature = static_cast<float>(static_cast<int>((metric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
// Only send data if temperature has changed and no error
@@ -10,7 +10,7 @@
#define RADIO_ID AUTO
#define RELAY_1 3 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
#define NUMBER_OF_RELAYS 2
#define NUMBER_OF_RELAYS 1
#define RELAY_ON 0
#define RELAY_OFF 1