ESP libraries
This commit is contained in:
@@ -36,13 +36,14 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// CORE
|
// CORE
|
||||||
#include "drivers/SPI/SPI.cpp"
|
|
||||||
|
|
||||||
|
|
||||||
// HARDWARE
|
// HARDWARE
|
||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
#if defined(ARDUINO_ARCH_ESP8266)
|
||||||
|
#include "drivers/ESP8266/SPI/SPI.cpp"
|
||||||
#include "core/MyHwESP8266.cpp"
|
#include "core/MyHwESP8266.cpp"
|
||||||
#elif defined(ARDUINO_ARCH_AVR)
|
#elif defined(ARDUINO_ARCH_AVR)
|
||||||
|
#include "drivers/AVR/SPI/SPI.cpp"
|
||||||
#include "core/MyHwATMega328.cpp"
|
#include "core/MyHwATMega328.cpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -66,26 +67,25 @@
|
|||||||
#define MY_RADIO_FEATURE
|
#define MY_RADIO_FEATURE
|
||||||
// SOFTSPI
|
// SOFTSPI
|
||||||
#ifdef MY_SOFTSPI
|
#ifdef MY_SOFTSPI
|
||||||
#include "drivers/DigitalIO/SoftI2cMaster.cpp"
|
#if defined(ARDUINO_ARCH_ESP8266)
|
||||||
#include "drivers/DigitalIO/PinIO.cpp"
|
#error Soft SPI is not available on ESP8266
|
||||||
|
#endif
|
||||||
|
#include "drivers/AVR/DigitalIO/SoftI2cMaster.cpp"
|
||||||
|
#include "drivers/AVR/DigitalIO/PinIO.cpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// FLASH
|
// FLASH
|
||||||
#ifdef MY_OTA_FIRMWARE_FEATURE
|
#ifdef MY_OTA_FIRMWARE_FEATURE
|
||||||
SPIFlash flash(MY_OTA_FLASH_SS, MY_OTA_FLASH_JDECID);
|
|
||||||
#include "drivers/SPIFlash/SPIFlash.cpp"
|
#include "drivers/SPIFlash/SPIFlash.cpp"
|
||||||
|
SPIFlash _flash(MY_OTA_FLASH_SS, MY_OTA_FLASH_JDECID);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "core/MyTransport.cpp"
|
|
||||||
#if defined(MY_RADIO_NRF24)
|
#if defined(MY_RADIO_NRF24)
|
||||||
#include "drivers/RF24/RF24.cpp"
|
#include "drivers/RF24/RF24.cpp"
|
||||||
#include "core/MyTransportNRF24.cpp"
|
#include "core/MyTransportNRF24.cpp"
|
||||||
MyTransportNRF24 transport;
|
|
||||||
|
|
||||||
#elif defined(MY_RADIO_RFM69)
|
#elif defined(MY_RADIO_RFM69)
|
||||||
#include "drivers/RFM69/RFM69.cpp"
|
#include "drivers/RFM69/RFM69.cpp"
|
||||||
#include "core/MyTransportRFM69.cpp"
|
#include "core/MyTransportRFM69.cpp"
|
||||||
MyTransportRFM69 transport;
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -93,10 +93,8 @@
|
|||||||
// GATEWAY - TRANSPORT
|
// GATEWAY - TRANSPORT
|
||||||
#if defined(MY_GATEWAY_FEATURE)
|
#if defined(MY_GATEWAY_FEATURE)
|
||||||
// GATEWAY - PROTOCOL
|
// GATEWAY - PROTOCOL
|
||||||
#include "core/MyProtocol.cpp"
|
|
||||||
#if defined(MY_GATEWAY_PROTOCOL_DEFAULT)
|
#if defined(MY_GATEWAY_PROTOCOL_DEFAULT)
|
||||||
#include "core/MyProtocolDefault.cpp"
|
#include "core/MyProtocolDefault.cpp"
|
||||||
MyProtocolDefault _protocol;
|
|
||||||
#else
|
#else
|
||||||
#error No gateway protocol specified!
|
#error No gateway protocol specified!
|
||||||
#endif
|
#endif
|
||||||
@@ -105,29 +103,29 @@
|
|||||||
#define MY_REPEATER_FEATURE
|
#define MY_REPEATER_FEATURE
|
||||||
#endif
|
#endif
|
||||||
#if defined(MY_GATEWAY_W5100_CLIENT) || defined(MY_GATEWAY_W5100_SERVER)
|
#if defined(MY_GATEWAY_W5100_CLIENT) || defined(MY_GATEWAY_W5100_SERVER)
|
||||||
#include "drivers/Ethernet_W5100/utility/socket.cpp"
|
#include "drivers/AVR/Ethernet_W5100/utility/socket.cpp"
|
||||||
#include "drivers/Ethernet_W5100/utility/w5100.cpp"
|
#include "drivers/AVR/Ethernet_W5100/utility/w5100.cpp"
|
||||||
#include "drivers/Ethernet_W5100/DNS.cpp"
|
#include "drivers/AVR/Ethernet_W5100/DNS.cpp"
|
||||||
#include "drivers/Ethernet_W5100/Ethernet.cpp"
|
#include "drivers/AVR/Ethernet_W5100/Ethernet.cpp"
|
||||||
#include "drivers/Ethernet_W5100/EthernetUdp.cpp"
|
#include "drivers/AVR/Ethernet_W5100/EthernetUdp.cpp"
|
||||||
#include "drivers/Ethernet_W5100/IPAddress.cpp"
|
#include "drivers/AVR/Ethernet_W5100/IPAddress.cpp"
|
||||||
|
|
||||||
#if !defined(MY_PORT)
|
#if !defined(MY_PORT)
|
||||||
#error You must define MY_PORT
|
#error You must define MY_PORT
|
||||||
#endif
|
#endif
|
||||||
#if !defined(USE_UDP)
|
#if !defined(USE_UDP)
|
||||||
#include "drivers/Ethernet_W5100/EthernetServer.cpp"
|
#include "drivers/AVR/Ethernet_W5100/EthernetServer.cpp"
|
||||||
#endif
|
#endif
|
||||||
#if defined(MY_GATEWAY_W5100_CLIENT) && !defined(MY_CONTROLLER_IP_ADDRESS)
|
#if defined(MY_GATEWAY_W5100_CLIENT) && !defined(MY_CONTROLLER_IP_ADDRESS)
|
||||||
#error You must define MY_CONTROLLER_IP_ADDRESS when acting as client
|
#error You must define MY_CONTROLLER_IP_ADDRESS when acting as client
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(MY_GATEWAY_W5100_CLIENT)
|
#if defined(MY_GATEWAY_W5100_CLIENT)
|
||||||
#include "drivers/Ethernet_W5100/EthernetClient.cpp"
|
#include "drivers/AVR/Ethernet_W5100/EthernetClient.cpp"
|
||||||
#include "core/MyGatewayTransportEthernet.cpp"
|
#include "core/MyGatewayTransportEthernet.cpp"
|
||||||
#endif
|
#endif
|
||||||
#elif defined(MY_GATEWAY_SERIAL)
|
#elif defined(MY_GATEWAY_SERIAL)
|
||||||
#include "core/MyGatewayTransportSerial.cpp"
|
#include "core/MyGatewayTransportSerial.cpp"
|
||||||
MyGatewayTransportSerial gwTransport(protocol);
|
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#undef MY_GATEWAY_FEATURE
|
#undef MY_GATEWAY_FEATURE
|
||||||
|
|||||||
+23
-5
@@ -5,8 +5,8 @@
|
|||||||
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
|
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
|
||||||
* network topology allowing messages to be routed to nodes.
|
* network topology allowing messages to be routed to nodes.
|
||||||
*
|
*
|
||||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
* Created by Tomas Hozza <thozza@gmail.com>
|
||||||
* Copyright (C) 2013-2015 Sensnology AB
|
* Copyright (C) 2015 Tomas Hozza
|
||||||
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||||
*
|
*
|
||||||
* Documentation: http://www.mysensors.org
|
* Documentation: http://www.mysensors.org
|
||||||
@@ -17,7 +17,25 @@
|
|||||||
* version 2 as published by the Free Software Foundation.
|
* version 2 as published by the Free Software Foundation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "MyTransport.h"
|
#ifndef MyGatewayTransport_h
|
||||||
|
#define MyGatewayTransport_h
|
||||||
|
|
||||||
MyTransport::MyTransport() {
|
#include "MyConfig.h"
|
||||||
}
|
#include "MyMessage.h"
|
||||||
|
#include "MyProtocol.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// initialize the driver
|
||||||
|
bool gatewayTransportBegin();
|
||||||
|
|
||||||
|
// Send message to controller
|
||||||
|
bool gatewayTransportSend(MyMessage &message);
|
||||||
|
|
||||||
|
// Check if a new message is available from controller
|
||||||
|
bool gatewayTransportAvailable();
|
||||||
|
|
||||||
|
// Pick up last message received from controller
|
||||||
|
MyMessage& gatewayTransportReceive();
|
||||||
|
|
||||||
|
#endif /* MyGatewayTransportEthernet_h */
|
||||||
@@ -64,7 +64,7 @@ bool gatewayTransportSend(MyMessage &message)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
_ethernetMsg = _protocol.format(message);
|
_ethernetMsg = protocolFormat(message);
|
||||||
#ifdef MY_USE_UDP
|
#ifdef MY_USE_UDP
|
||||||
_ethernetServer.beginPacket(_ethernetControllerIP, MY_CONTROLLER_PORT);
|
_ethernetServer.beginPacket(_ethernetControllerIP, MY_CONTROLLER_PORT);
|
||||||
_ethernetServer.write(_ethernetMsg, strlen(_ethernetMsg));
|
_ethernetServer.write(_ethernetMsg, strlen(_ethernetMsg));
|
||||||
@@ -128,7 +128,7 @@ bool gatewayTransportAvailable()
|
|||||||
|
|
||||||
if (available) {
|
if (available) {
|
||||||
// Parse message and return parse result
|
// Parse message and return parse result
|
||||||
available = _protocol.parse(_ethernetMsg, _ethernetInputBuffer);
|
available = protocolParse(_ethernetMsg, _ethernetInputBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
return available;
|
return available;
|
||||||
|
|||||||
@@ -24,36 +24,19 @@
|
|||||||
#include "MyMessage.h"
|
#include "MyMessage.h"
|
||||||
#include "MyProtocol.h"
|
#include "MyProtocol.h"
|
||||||
#include "MyProtocolDefault.h"
|
#include "MyProtocolDefault.h"
|
||||||
|
#include "MyGatewayTransport.h"
|
||||||
|
|
||||||
#include "drivers/Ethernet_W5100/IPAddress.h"
|
|
||||||
|
|
||||||
// Use this if you have attached a Ethernet ENC28J60 shields
|
// Use this if you have attached a Ethernet ENC28J60 shields
|
||||||
//#include <UIPEthernet.h>
|
//#include <UIPEthernet.h>
|
||||||
|
|
||||||
// Use this fo WizNET W5100 module and Arduino Ethernet Shield
|
|
||||||
#include "drivers/Ethernet_W5100/Ethernet.h"
|
|
||||||
|
|
||||||
#ifdef MY_USE_UDP
|
|
||||||
#include "drivers/Ethernet_W5100/EthernetUdp.h"
|
|
||||||
#endif /* MY_USE_UDP */
|
|
||||||
|
|
||||||
#define CONTROLLER_PORT 5003
|
#define CONTROLLER_PORT 5003
|
||||||
#define IP_RENEWAL_INTERVAL 60000 // in milliseconds
|
#define IP_RENEWAL_INTERVAL 60000 // in milliseconds
|
||||||
#define MAX_RECEIVE_LENGTH 100 // Maximum message length for messages coming from controller
|
#define MAX_RECEIVE_LENGTH 100 // Maximum message length for messages coming from controller
|
||||||
|
|
||||||
|
|
||||||
// initialize the driver
|
|
||||||
bool gatewayTransportBegin();
|
|
||||||
|
|
||||||
// Send message to controller
|
|
||||||
bool gatewayTransportSend(MyMessage &message);
|
|
||||||
|
|
||||||
// Check if a new message is available from controller
|
|
||||||
bool gatewayTransportAvailable();
|
|
||||||
|
|
||||||
// Pick up last message received from controller
|
|
||||||
MyMessage& gatewayTransportReceive();
|
|
||||||
|
|
||||||
#ifndef MY_IP_ADDRESS
|
#ifndef MY_IP_ADDRESS
|
||||||
void gatewayTransportRenewIP();
|
void gatewayTransportRenewIP();
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -17,54 +17,55 @@
|
|||||||
* version 2 as published by the Free Software Foundation.
|
* version 2 as published by the Free Software Foundation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "MyGatewayTransportSerial.h"
|
#include "MyGatewayTransportSerial.h"
|
||||||
|
|
||||||
|
char _serialInputString[MAX_RECEIVE_LENGTH]; // A buffer for incoming commands from serial interface
|
||||||
|
int _serialInputPos;
|
||||||
|
MyMessage _serialMsg;
|
||||||
|
|
||||||
MyGatewayTransportSerial::MyGatewayTransportSerial(MyProtocol &_protocol) : MyGatewayTransport(_protocol),inputPos(0)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MyGatewayTransportSerial::begin() {
|
bool gatewayTransportBegin() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MyGatewayTransportSerial::send(MyMessage &message) {
|
bool gatewayTransportSend(MyMessage &message) {
|
||||||
Serial.print(protocol.format(message));
|
Serial.print(protocolFormat(message));
|
||||||
// Serial print is always successful
|
// Serial print is always successful
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MyGatewayTransportSerial::available() {
|
bool gatewayTransportAvailable() {
|
||||||
bool available = false;
|
bool available = false;
|
||||||
while (Serial.available()) {
|
while (Serial.available()) {
|
||||||
// get the new byte:
|
// get the new byte:
|
||||||
char inChar = (char) Serial.read();
|
char inChar = (char) Serial.read();
|
||||||
// if the incoming character is a newline, set a flag
|
// if the incoming character is a newline, set a flag
|
||||||
// so the main loop can do something about it:
|
// so the main loop can do something about it:
|
||||||
if (inputPos < MAX_RECEIVE_LENGTH - 1 && !available) {
|
if (_serialInputPos < MAX_RECEIVE_LENGTH - 1 && !available) {
|
||||||
if (inChar == '\n') {
|
if (inChar == '\n') {
|
||||||
inputString[inputPos] = 0;
|
_serialInputString[_serialInputPos] = 0;
|
||||||
available = true;
|
available = true;
|
||||||
} else {
|
} else {
|
||||||
// add it to the inputString:
|
// add it to the inputString:
|
||||||
inputString[inputPos] = inChar;
|
_serialInputString[_serialInputPos] = inChar;
|
||||||
inputPos++;
|
_serialInputPos++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Incoming message too long. Throw away
|
// Incoming message too long. Throw away
|
||||||
inputPos = 0;
|
_serialInputPos = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (available) {
|
if (available) {
|
||||||
// Parse message and return parse result
|
// Parse message and return parse result
|
||||||
available = protocol.parse(msg, inputString);
|
available = protocolParse(_serialMsg, _serialInputString);
|
||||||
inputPos = 0;
|
_serialInputPos = 0;
|
||||||
}
|
}
|
||||||
return available;
|
return available;
|
||||||
}
|
}
|
||||||
|
|
||||||
MyMessage & MyGatewayTransportSerial::receive() {
|
MyMessage & gatewayTransportReceive() {
|
||||||
// Return the last parsed message
|
// Return the last parsed message
|
||||||
return msg;
|
return _serialMsg;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,32 +21,10 @@
|
|||||||
#define MyGatewayTransportSerial_h
|
#define MyGatewayTransportSerial_h
|
||||||
|
|
||||||
#include "MyMessage.h"
|
#include "MyMessage.h"
|
||||||
|
#include "MyGatewayTransport.h"
|
||||||
#include "MyProtocol.h"
|
#include "MyProtocol.h"
|
||||||
#include "MyProtocolDefault.h"
|
#include "MyProtocolDefault.h"
|
||||||
|
|
||||||
#define MAX_RECEIVE_LENGTH 100 // Maximum message length for messages coming from controller
|
#define MAX_RECEIVE_LENGTH 100 // Maximum message length for messages coming from controller
|
||||||
|
|
||||||
class MyGatewayTransportSerial : public MyGatewayTransport
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
// MyGateway constructor
|
|
||||||
MyGatewayTransportSerial(MyProtocol &protocol = *new MyProtocolDefault());
|
|
||||||
|
|
||||||
// initialize the transport driver
|
|
||||||
bool begin();
|
|
||||||
|
|
||||||
// Send message to controller
|
|
||||||
bool send(MyMessage &message);
|
|
||||||
|
|
||||||
// Check if a new message is available from controller
|
|
||||||
bool available();
|
|
||||||
|
|
||||||
// Pick up last message received from controller
|
|
||||||
MyMessage& receive();
|
|
||||||
private:
|
|
||||||
char inputString[MAX_RECEIVE_LENGTH]; // A buffer for incoming commands from serial interface
|
|
||||||
int inputPos;
|
|
||||||
MyMessage msg;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
/**
|
||||||
|
* The MySensors Arduino library handles the wireless radio link and protocol
|
||||||
|
* between your home built sensors/actuators and HA controller of choice.
|
||||||
|
* The sensors forms a self healing radio network with optional repeaters. Each
|
||||||
|
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
|
||||||
|
* network topology allowing messages to be routed to nodes.
|
||||||
|
*
|
||||||
|
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||||
|
* Copyright (C) 2013-2015 Sensnology AB
|
||||||
|
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||||
|
*
|
||||||
|
* Documentation: http://www.mysensors.org
|
||||||
|
* Support Forum: http://forum.mysensors.org
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* version 2 as published by the Free Software Foundation.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MyHw_h
|
||||||
|
#define MyHw_h
|
||||||
|
|
||||||
|
#include "MyConfig.h"
|
||||||
|
#include "MyMessage.h"
|
||||||
|
#include "MyHw.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#include <Arduino.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Implement these as functions or macros
|
||||||
|
/*
|
||||||
|
#define hwDigitalWrite(__pin, __value)
|
||||||
|
#define hwInit() Serial.begin(BAUD_RATE)
|
||||||
|
#define hwWatchdogReset() wdt_reset()
|
||||||
|
#define hwReboot() wdt_enable(WDTO_15MS); while (1)
|
||||||
|
#define hwMillis() millis()
|
||||||
|
|
||||||
|
void hwReadConfigBlock(void* buf, void* adr, size_t length);
|
||||||
|
void hwWriteConfigBlock(void* buf, void* adr, size_t length);
|
||||||
|
void hwWriteConfig(int adr, uint8_t value);
|
||||||
|
uint8_t hwReadConfig(int adr);
|
||||||
|
*/
|
||||||
|
|
||||||
|
void hwSleep(unsigned long ms);
|
||||||
|
bool hwSleep(uint8_t interrupt, uint8_t mode, unsigned long ms);
|
||||||
|
uint8_t hwSleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms);
|
||||||
|
#ifdef MY_DEBUG
|
||||||
|
void hwDebugPrint(const char *fmt, ... );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // #ifdef ARDUINO_ARCH_ESP8266
|
||||||
@@ -20,8 +20,7 @@
|
|||||||
#ifndef MyHwATMega328_h
|
#ifndef MyHwATMega328_h
|
||||||
#define MyHwATMega328_h
|
#define MyHwATMega328_h
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_AVR
|
#include "MyHw.h"
|
||||||
|
|
||||||
#include "MyConfig.h"
|
#include "MyConfig.h"
|
||||||
#include "MyMessage.h"
|
#include "MyMessage.h"
|
||||||
#include <avr/eeprom.h>
|
#include <avr/eeprom.h>
|
||||||
@@ -92,14 +91,6 @@ enum period_t
|
|||||||
SLEEP_FOREVER
|
SLEEP_FOREVER
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void hwSleep(unsigned long ms);
|
|
||||||
bool hwSleep(uint8_t interrupt, uint8_t mode, unsigned long ms);
|
|
||||||
uint8_t hwSleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms);
|
|
||||||
#ifdef MY_DEBUG
|
|
||||||
void hwDebugPrint(const char *fmt, ... );
|
|
||||||
#endif
|
|
||||||
void hwInternalSleep(unsigned long ms);
|
void hwInternalSleep(unsigned long ms);
|
||||||
|
|
||||||
#endif // #ifdef ARDUINO_ARCH_AVR
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -17,10 +17,8 @@
|
|||||||
* version 2 as published by the Free Software Foundation.
|
* version 2 as published by the Free Software Foundation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
|
|
||||||
#include "MyHwESP8266.h"
|
#include "MyHwESP8266.h"
|
||||||
#include <EEPROM.h>
|
#include "drivers/ESP8266/EEPROM/EEPROM.cpp"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
int8_t pinIntTrigger = 0;
|
int8_t pinIntTrigger = 0;
|
||||||
@@ -54,7 +52,7 @@ static void hwInitConfigBlock( size_t length = 1024 /*ATMega328 has 1024 bytes*/
|
|||||||
|
|
||||||
void hwReadConfigBlock(void* buf, void* adr, size_t length)
|
void hwReadConfigBlock(void* buf, void* adr, size_t length)
|
||||||
{
|
{
|
||||||
hw_initConfigBlock();
|
hwInitConfigBlock();
|
||||||
uint8_t* dst = static_cast<uint8_t*>(buf);
|
uint8_t* dst = static_cast<uint8_t*>(buf);
|
||||||
int offs = reinterpret_cast<int>(adr);
|
int offs = reinterpret_cast<int>(adr);
|
||||||
while (length-- > 0)
|
while (length-- > 0)
|
||||||
@@ -65,7 +63,7 @@ void hwReadConfigBlock(void* buf, void* adr, size_t length)
|
|||||||
|
|
||||||
void hwWriteConfigBlock(void* buf, void* adr, size_t length)
|
void hwWriteConfigBlock(void* buf, void* adr, size_t length)
|
||||||
{
|
{
|
||||||
hw_initConfigBlock();
|
hwInitConfigBlock();
|
||||||
uint8_t* src = static_cast<uint8_t*>(buf);
|
uint8_t* src = static_cast<uint8_t*>(buf);
|
||||||
int offs = reinterpret_cast<int>(adr);
|
int offs = reinterpret_cast<int>(adr);
|
||||||
while (length-- > 0)
|
while (length-- > 0)
|
||||||
@@ -78,16 +76,16 @@ void hwWriteConfigBlock(void* buf, void* adr, size_t length)
|
|||||||
uint8_t hwReadConfig(int adr)
|
uint8_t hwReadConfig(int adr)
|
||||||
{
|
{
|
||||||
uint8_t value;
|
uint8_t value;
|
||||||
hw_readConfigBlock(&value, reinterpret_cast<void*>(adr), 1);
|
hwReadConfigBlock(&value, reinterpret_cast<void*>(adr), 1);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hwWriteConfig(int adr, uint8_t value)
|
void hwWriteConfig(int adr, uint8_t value)
|
||||||
{
|
{
|
||||||
uint8_t curr = hw_readConfig(adr);
|
uint8_t curr = hwReadConfig(adr);
|
||||||
if (curr != value)
|
if (curr != value)
|
||||||
{
|
{
|
||||||
hw_writeConfigBlock(&value, reinterpret_cast<void*>(adr), 1);
|
hwWriteConfigBlock(&value, reinterpret_cast<void*>(adr), 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,7 +107,7 @@ uint8_t hwSleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t m
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MY_DEBUG
|
#ifdef MY_DEBUG
|
||||||
void hwDebugPrint(bool isGW, const char *fmt, ... ) {
|
void hwDebugPrint(const char *fmt, ... ) {
|
||||||
char fmtBuffer[300];
|
char fmtBuffer[300];
|
||||||
#ifdef MY_GATEWAY_FEATURE
|
#ifdef MY_GATEWAY_FEATURE
|
||||||
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
|
// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
|
||||||
@@ -134,5 +132,3 @@ void hwDebugPrint(bool isGW, const char *fmt, ... ) {
|
|||||||
//Serial.write(freeRam());
|
//Serial.write(freeRam());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // #ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
|
|||||||
@@ -16,25 +16,23 @@
|
|||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
* version 2 as published by the Free Software Foundation.
|
* version 2 as published by the Free Software Foundation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
|
|
||||||
#ifndef MyHwESP8266_h
|
#ifndef MyHwESP8266_h
|
||||||
#define MyHwESP8266_h
|
#define MyHwESP8266_h
|
||||||
|
|
||||||
|
#include "MyHw.h"
|
||||||
#include "MyConfig.h"
|
#include "MyConfig.h"
|
||||||
#include "MyMessage.h"
|
#include "MyMessage.h"
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <SPI.h>
|
//#include <SPI.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Define these as macros to save valuable space
|
// Define these as macros to save valuable space
|
||||||
|
|
||||||
#define hwDigitalWrite(__pin, __value) (digitalWrite(__pin, __value))
|
#define hwDigitalWrite(__pin, __value) (digitalWrite(__pin, __value))
|
||||||
#define hwInit() Serial.begin(BAUD_RATE)
|
#define hwInit() Serial.begin(MY_BAUD_RATE)
|
||||||
#define hwWatchdogReset() wdt_reset()
|
#define hwWatchdogReset() wdt_reset()
|
||||||
#define hwReboot() wdt_enable(WDTO_15MS); while (1)
|
#define hwReboot() wdt_enable(WDTO_15MS); while (1)
|
||||||
#define hwMillis() millis()
|
#define hwMillis() millis()
|
||||||
@@ -44,28 +42,5 @@ void hwWriteConfigBlock(void* buf, void* adr, size_t length);
|
|||||||
void hwWriteConfig(int adr, uint8_t value);
|
void hwWriteConfig(int adr, uint8_t value);
|
||||||
uint8_t hwReadConfig(int adr);
|
uint8_t hwReadConfig(int adr);
|
||||||
|
|
||||||
enum period_t
|
|
||||||
{
|
|
||||||
SLEEP_15Ms,
|
|
||||||
SLEEP_30MS,
|
|
||||||
SLEEP_60MS,
|
|
||||||
SLEEP_120MS,
|
|
||||||
SLEEP_250MS,
|
|
||||||
SLEEP_500MS,
|
|
||||||
SLEEP_1S,
|
|
||||||
SLEEP_2S,
|
|
||||||
SLEEP_4S,
|
|
||||||
SLEEP_8S,
|
|
||||||
SLEEP_FOREVER
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void hwSleep(unsigned long ms);
|
|
||||||
bool hwSleep(uint8_t interrupt, uint8_t mode, unsigned long ms);
|
|
||||||
uint8_t hwSleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms);
|
|
||||||
#ifdef MY_DEBUG
|
|
||||||
void hwDebugPrint(const char *fmt, ... );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // #ifdef ARDUINO_ARCH_ESP8266
|
#endif // #ifdef ARDUINO_ARCH_ESP8266
|
||||||
|
|||||||
@@ -22,18 +22,12 @@
|
|||||||
|
|
||||||
#include "MyMessage.h"
|
#include "MyMessage.h"
|
||||||
|
|
||||||
class MyProtocol
|
// parse(message, inputString)
|
||||||
{
|
// parse a string into a message element
|
||||||
public:
|
// returns true if successfully parsed the input string
|
||||||
// MyProtocol constructor
|
bool protocolParse(MyMessage &message, char *inputString);
|
||||||
MyProtocol();
|
|
||||||
// parse(message, inputString)
|
|
||||||
// parse a string into a message element
|
|
||||||
// returns true if successfully parsed the input string
|
|
||||||
virtual bool parse(MyMessage &message, char *inputString) = 0;
|
|
||||||
|
|
||||||
// Format MyMessage to the protocol represenataion
|
// Format MyMessage to the protocol represenataion
|
||||||
virtual char *format(MyMessage &message) = 0;
|
char *protocolFormat(MyMessage &message);
|
||||||
|
|
||||||
};
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -21,9 +21,10 @@
|
|||||||
#include "MyProtocolDefault.h"
|
#include "MyProtocolDefault.h"
|
||||||
#include "MyTransport.h"
|
#include "MyTransport.h"
|
||||||
|
|
||||||
MyProtocolDefault::MyProtocolDefault() : MyProtocol() {}
|
char fmtBuffer[MAX_FORMAT_BUFFER_LENGTH];
|
||||||
|
char convBuffer[MAX_PAYLOAD*2+1];
|
||||||
|
|
||||||
bool MyProtocolDefault::parse(MyMessage &message, char *inputString) {
|
bool protocolParse(MyMessage &message, char *inputString) {
|
||||||
char *str, *p, *value=NULL;
|
char *str, *p, *value=NULL;
|
||||||
uint8_t bvalue[MAX_PAYLOAD];
|
uint8_t bvalue[MAX_PAYLOAD];
|
||||||
uint8_t blen = 0;
|
uint8_t blen = 0;
|
||||||
@@ -58,8 +59,8 @@ bool MyProtocolDefault::parse(MyMessage &message, char *inputString) {
|
|||||||
blen = 0;
|
blen = 0;
|
||||||
uint8_t val;
|
uint8_t val;
|
||||||
while (*str) {
|
while (*str) {
|
||||||
val = h2i(*str++) << 4;
|
val = protocolH2i(*str++) << 4;
|
||||||
val += h2i(*str++);
|
val += protocolH2i(*str++);
|
||||||
bvalue[blen] = val;
|
bvalue[blen] = val;
|
||||||
blen++;
|
blen++;
|
||||||
}
|
}
|
||||||
@@ -89,13 +90,12 @@ bool MyProtocolDefault::parse(MyMessage &message, char *inputString) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
char * MyProtocolDefault::format(MyMessage &message) {
|
char * protocolFormat(MyMessage &message) {
|
||||||
snprintf_P(fmtBuffer, MAX_FORMAT_BUFFER_LENGTH, PSTR("%d;%d;%d;%d;%d;%s\n"), message.sender, message.sensor, mGetCommand(message), mGetAck(message), message.type, message.getString(convBuffer));
|
snprintf_P(fmtBuffer, MAX_FORMAT_BUFFER_LENGTH, PSTR("%d;%d;%d;%d;%d;%s\n"), message.sender, message.sensor, mGetCommand(message), mGetAck(message), message.type, message.getString(convBuffer));
|
||||||
return fmtBuffer;
|
return fmtBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t protocolH2i(char c) {
|
||||||
uint8_t MyProtocolDefault::h2i(char c) {
|
|
||||||
uint8_t i = 0;
|
uint8_t i = 0;
|
||||||
if (c <= '9')
|
if (c <= '9')
|
||||||
i += c - '0';
|
i += c - '0';
|
||||||
@@ -105,3 +105,5 @@ uint8_t MyProtocolDefault::h2i(char c) {
|
|||||||
i += c - 'A' + 10;
|
i += c - 'A' + 10;
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -21,22 +21,10 @@
|
|||||||
#define MyProtocolDefault_h
|
#define MyProtocolDefault_h
|
||||||
|
|
||||||
#include "MyConfig.h"
|
#include "MyConfig.h"
|
||||||
#include "MyProtocol.h"
|
|
||||||
#include "MyTransport.h"
|
#include "MyTransport.h"
|
||||||
|
|
||||||
#define MAX_FORMAT_BUFFER_LENGTH 120 // Max buffersize when formatting messages
|
#define MAX_FORMAT_BUFFER_LENGTH 120 // Max buffersize when formatting messages
|
||||||
|
|
||||||
|
uint8_t protocolH2i(char c);
|
||||||
|
|
||||||
class MyProtocolDefault : public MyProtocol
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
MyProtocolDefault();
|
|
||||||
bool parse(MyMessage &message, char *inputString);
|
|
||||||
char *format(MyMessage &message);
|
|
||||||
private:
|
|
||||||
char fmtBuffer[MAX_FORMAT_BUFFER_LENGTH];
|
|
||||||
char convBuffer[MAX_PAYLOAD*2+1];
|
|
||||||
|
|
||||||
uint8_t h2i(char c);
|
|
||||||
};
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ bool isValidFirmware() {
|
|||||||
// init crc
|
// init crc
|
||||||
uint16_t crc = ~0;
|
uint16_t crc = ~0;
|
||||||
for (uint16_t i = 0; i < _fc.blocks * FIRMWARE_BLOCK_SIZE; ++i) {
|
for (uint16_t i = 0; i < _fc.blocks * FIRMWARE_BLOCK_SIZE; ++i) {
|
||||||
crc ^= flash.readByte(i + FIRMWARE_START_OFFSET);
|
crc ^= _flash.readByte(i + FIRMWARE_START_OFFSET);
|
||||||
for (int8_t j = 0; j < 8; ++j) {
|
for (int8_t j = 0; j < 8; ++j) {
|
||||||
if (crc & 1)
|
if (crc & 1)
|
||||||
crc = (crc >> 1) ^ 0xA001;
|
crc = (crc >> 1) ^ 0xA001;
|
||||||
@@ -217,7 +217,7 @@ void begin() {
|
|||||||
_failedTransmissions = 0;
|
_failedTransmissions = 0;
|
||||||
|
|
||||||
// Setup radio
|
// Setup radio
|
||||||
if (!transport.init()) {
|
if (!transportInit()) {
|
||||||
debug(PSTR("radio init fail\n"));
|
debug(PSTR("radio init fail\n"));
|
||||||
while(1); // Nothing more we can do
|
while(1); // Nothing more we can do
|
||||||
}
|
}
|
||||||
@@ -311,7 +311,7 @@ ControllerConfig getConfig() {
|
|||||||
#if defined(MY_RADIO_FEATURE)
|
#if defined(MY_RADIO_FEATURE)
|
||||||
void requestNodeId() {
|
void requestNodeId() {
|
||||||
debug(PSTR("req id\n"));
|
debug(PSTR("req id\n"));
|
||||||
transport.setAddress(_nc.nodeId);
|
transportSetAddress(_nc.nodeId);
|
||||||
build(_msg, _nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_ID_REQUEST, false).set("");
|
build(_msg, _nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_ID_REQUEST, false).set("");
|
||||||
sendWrite(_nc.parentNodeId, _msg);
|
sendWrite(_nc.parentNodeId, _msg);
|
||||||
wait(2000);
|
wait(2000);
|
||||||
@@ -323,7 +323,7 @@ void requestNodeId() {
|
|||||||
|
|
||||||
void setupNode() {
|
void setupNode() {
|
||||||
// Open reading pipe for messages directed to this node (set write pipe to same)
|
// Open reading pipe for messages directed to this node (set write pipe to same)
|
||||||
transport.setAddress(_nc.nodeId);
|
transportSetAddress(_nc.nodeId);
|
||||||
// Present node and request config
|
// Present node and request config
|
||||||
#ifndef MY_GATEWAY_FEATURE
|
#ifndef MY_GATEWAY_FEATURE
|
||||||
if (_nc.nodeId != AUTO) {
|
if (_nc.nodeId != AUTO) {
|
||||||
@@ -563,7 +563,7 @@ boolean sendWrite(uint8_t to, MyMessage &message) {
|
|||||||
#ifdef MY_LEDS_BLINKING_FEATURE
|
#ifdef MY_LEDS_BLINKING_FEATURE
|
||||||
txBlink(1);
|
txBlink(1);
|
||||||
#endif
|
#endif
|
||||||
bool ok = transport.send(to, &message, min(MAX_MESSAGE_LENGTH, HEADER_SIZE + length));
|
bool ok = transportSend(to, &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,sg=%d,st=%s:%s\n"),
|
debug(PSTR("send: %d-%d-%d-%d s=%d,c=%d,t=%d,pt=%d,l=%d,sg=%d,st=%s:%s\n"),
|
||||||
message.sender,message.last, to, message.destination, message.sensor, mGetCommand(message), message.type,
|
message.sender,message.last, to, message.destination, message.sensor, mGetCommand(message), message.type,
|
||||||
@@ -660,7 +660,7 @@ void process() {
|
|||||||
|
|
||||||
#if defined(MY_RADIO_FEATURE)
|
#if defined(MY_RADIO_FEATURE)
|
||||||
uint8_t to = 0;
|
uint8_t to = 0;
|
||||||
if (!transport.available(&to))
|
if (!transportAvailable(&to))
|
||||||
{
|
{
|
||||||
#ifdef MY_OTA_FIRMWARE_FEATURE
|
#ifdef MY_OTA_FIRMWARE_FEATURE
|
||||||
unsigned long enter = hwMillis();
|
unsigned long enter = hwMillis();
|
||||||
@@ -692,7 +692,7 @@ void process() {
|
|||||||
(void)signer.checkTimer(); // Manage signing timeout
|
(void)signer.checkTimer(); // Manage signing timeout
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint8_t len = transport.receive((uint8_t *)&_msg);
|
uint8_t len = transportReceive((uint8_t *)&_msg);
|
||||||
(void)len; //until somebody makes use of 'len'
|
(void)len; //until somebody makes use of 'len'
|
||||||
#ifdef MY_LEDS_BLINKING_FEATURE
|
#ifdef MY_LEDS_BLINKING_FEATURE
|
||||||
rxBlink(1);
|
rxBlink(1);
|
||||||
@@ -842,14 +842,14 @@ void process() {
|
|||||||
// copy new FW config
|
// copy new FW config
|
||||||
memcpy(&_fc,firmwareConfigResponse,sizeof(NodeFirmwareConfig));
|
memcpy(&_fc,firmwareConfigResponse,sizeof(NodeFirmwareConfig));
|
||||||
// Init flash
|
// Init flash
|
||||||
if (!flash.initialize()) {
|
if (!_flash.initialize()) {
|
||||||
debug(PSTR("flash init fail\n"));
|
debug(PSTR("flash init fail\n"));
|
||||||
_fwUpdateOngoing = false;
|
_fwUpdateOngoing = false;
|
||||||
} else {
|
} else {
|
||||||
// erase lower 32K -> max flash size for ATMEGA328
|
// erase lower 32K -> max flash size for ATMEGA328
|
||||||
flash.blockErase32K(0);
|
_flash.blockErase32K(0);
|
||||||
// wait until flash erased
|
// wait until flash erased
|
||||||
while ( flash.busy() );
|
while ( _flash.busy() );
|
||||||
_fwBlock = _fc.blocks;
|
_fwBlock = _fc.blocks;
|
||||||
_fwUpdateOngoing = true;
|
_fwUpdateOngoing = true;
|
||||||
// reset flags
|
// reset flags
|
||||||
@@ -865,9 +865,9 @@ void process() {
|
|||||||
// extract FW block
|
// extract FW block
|
||||||
ReplyFWBlock *firmwareResponse = (ReplyFWBlock *)_msg.data;
|
ReplyFWBlock *firmwareResponse = (ReplyFWBlock *)_msg.data;
|
||||||
// write to flash
|
// write to flash
|
||||||
flash.writeBytes( ((_fwBlock - 1) * FIRMWARE_BLOCK_SIZE) + FIRMWARE_START_OFFSET, firmwareResponse->data, FIRMWARE_BLOCK_SIZE);
|
_flash.writeBytes( ((_fwBlock - 1) * FIRMWARE_BLOCK_SIZE) + FIRMWARE_START_OFFSET, firmwareResponse->data, FIRMWARE_BLOCK_SIZE);
|
||||||
// wait until flash written
|
// wait until flash written
|
||||||
while ( flash.busy() );
|
while ( _flash.busy() );
|
||||||
_fwBlock--;
|
_fwBlock--;
|
||||||
if (!_fwBlock) {
|
if (!_fwBlock) {
|
||||||
// We're finished! Do a checksum and reboot.
|
// We're finished! Do a checksum and reboot.
|
||||||
@@ -877,7 +877,7 @@ void process() {
|
|||||||
// All seems ok, write size and signature to flash (DualOptiboot will pick this up and flash it)
|
// All seems ok, write size and signature to flash (DualOptiboot will pick this up and flash it)
|
||||||
uint16_t fwsize = FIRMWARE_BLOCK_SIZE * _fc.blocks;
|
uint16_t fwsize = FIRMWARE_BLOCK_SIZE * _fc.blocks;
|
||||||
uint8_t OTAbuffer[10] = {'F','L','X','I','M','G',':',(fwsize >> 8),fwsize,':'};
|
uint8_t OTAbuffer[10] = {'F','L','X','I','M','G',':',(fwsize >> 8),fwsize,':'};
|
||||||
flash.writeBytes(0, OTAbuffer, 10);
|
_flash.writeBytes(0, OTAbuffer, 10);
|
||||||
// Write the new firmware config to eeprom
|
// Write the new firmware config to eeprom
|
||||||
hwWriteConfigBlock((void*)&_fc, (void*)EEPROM_FIRMWARE_TYPE_ADDRESS, sizeof(NodeFirmwareConfig));
|
hwWriteConfigBlock((void*)&_fc, (void*)EEPROM_FIRMWARE_TYPE_ADDRESS, sizeof(NodeFirmwareConfig));
|
||||||
hwReboot();
|
hwReboot();
|
||||||
@@ -986,7 +986,7 @@ void sleep(unsigned long ms) {
|
|||||||
} else {
|
} else {
|
||||||
#endif
|
#endif
|
||||||
#if defined(MY_RADIO_FEATURE)
|
#if defined(MY_RADIO_FEATURE)
|
||||||
transport.powerDown();
|
transportPowerDown();
|
||||||
#endif
|
#endif
|
||||||
hwSleep(ms);
|
hwSleep(ms);
|
||||||
#if defined(MY_OTA_FIRMWARE_FEATURE)
|
#if defined(MY_OTA_FIRMWARE_FEATURE)
|
||||||
@@ -1003,7 +1003,7 @@ bool sleep(uint8_t interrupt, uint8_t mode, unsigned long ms) {
|
|||||||
} else {
|
} else {
|
||||||
#endif
|
#endif
|
||||||
#if defined(MY_RADIO_FEATURE)
|
#if defined(MY_RADIO_FEATURE)
|
||||||
transport.powerDown();
|
transportPowerDown();
|
||||||
#endif
|
#endif
|
||||||
return hwSleep(interrupt, mode, ms) ;
|
return hwSleep(interrupt, mode, ms) ;
|
||||||
#if defined(MY_OTA_FIRMWARE_FEATURE)
|
#if defined(MY_OTA_FIRMWARE_FEATURE)
|
||||||
@@ -1020,7 +1020,7 @@ int8_t sleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode
|
|||||||
} else {
|
} else {
|
||||||
#endif
|
#endif
|
||||||
#if defined(MY_RADIO_FEATURE)
|
#if defined(MY_RADIO_FEATURE)
|
||||||
transport.powerDown();
|
transportPowerDown();
|
||||||
#endif
|
#endif
|
||||||
return hwSleep(interrupt1, mode1, interrupt2, mode2, ms) ;
|
return hwSleep(interrupt1, mode1, interrupt2, mode2, ms) ;
|
||||||
#if defined(MY_OTA_FIRMWARE_FEATURE)
|
#if defined(MY_OTA_FIRMWARE_FEATURE)
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
|
|
||||||
#include "Version.h" // Auto generated by bot
|
#include "Version.h" // Auto generated by bot
|
||||||
#include "MyConfig.h"
|
#include "MyConfig.h"
|
||||||
#include "MyTransport.h"
|
|
||||||
#ifdef MY_SIGNING_FEATURE
|
#ifdef MY_SIGNING_FEATURE
|
||||||
#include "MySigning.h"
|
#include "MySigning.h"
|
||||||
#include "MySigningNone.h"
|
#include "MySigningNone.h"
|
||||||
|
|||||||
@@ -29,37 +29,5 @@
|
|||||||
#define GATEWAY_ADDRESS ((uint8_t)0)
|
#define GATEWAY_ADDRESS ((uint8_t)0)
|
||||||
#define BROADCAST_ADDRESS ((uint8_t)0xFF)
|
#define BROADCAST_ADDRESS ((uint8_t)0xFF)
|
||||||
|
|
||||||
class MyTransport
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
// MyTransport 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
|
|
||||||
MyTransport();
|
|
||||||
// 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
|
|
||||||
virtual bool init() = 0;
|
|
||||||
// setAddress(address)
|
|
||||||
// set the node address and start listening to that address (and the broadcast address)
|
|
||||||
virtual void setAddress(uint8_t address) = 0;
|
|
||||||
// getAddress()
|
|
||||||
// returns the current address from the radio driver
|
|
||||||
virtual uint8_t getAddress() = 0;
|
|
||||||
// send(to, data, len)
|
|
||||||
// reliable transmission of the data with given length (in bytes) to the destination address
|
|
||||||
// returns true if successfully submitted
|
|
||||||
virtual bool send(uint8_t to, const void* data, uint8_t len) = 0;
|
|
||||||
// available(to)
|
|
||||||
// returns true if a new packet arrived in the rx buffer
|
|
||||||
// populates "to" parameter with the address the packet was sent to (either own address or broadcast)
|
|
||||||
virtual bool available(uint8_t *to) = 0;
|
|
||||||
// receive(data)
|
|
||||||
// returns length of received packet
|
|
||||||
// populates "data" parameter with received data
|
|
||||||
virtual uint8_t receive(void* data) = 0;
|
|
||||||
// powers down the radio
|
|
||||||
virtual void powerDown() = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -17,76 +17,72 @@
|
|||||||
* version 2 as published by the Free Software Foundation.
|
* version 2 as published by the Free Software Foundation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "MyTransport.h"
|
|
||||||
#include "MyTransportNRF24.h"
|
#include "MyTransportNRF24.h"
|
||||||
|
|
||||||
MyTransportNRF24::MyTransportNRF24()
|
RF24 _rf24(MY_RF24_CE_PIN, MY_RF24_CS_PIN);
|
||||||
:
|
uint8_t _address;
|
||||||
MyTransport(),
|
uint8_t _paLevel;
|
||||||
rf24(MY_RF24_CE_PIN, MY_RF24_CS_PIN)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MyTransportNRF24::init() {
|
bool transportInit() {
|
||||||
// Start up the radio library
|
// Start up the radio library
|
||||||
rf24.begin();
|
_rf24.begin();
|
||||||
|
|
||||||
if (!rf24.isPVariant()) {
|
if (!_rf24.isPVariant()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
rf24.setAutoAck(1);
|
_rf24.setAutoAck(1);
|
||||||
rf24.setAutoAck(BROADCAST_PIPE,false); // Turn off auto ack for broadcast
|
_rf24.setAutoAck(BROADCAST_PIPE,false); // Turn off auto ack for broadcast
|
||||||
rf24.enableAckPayload();
|
_rf24.enableAckPayload();
|
||||||
rf24.setChannel(MY_RF24_CHANNEL);
|
_rf24.setChannel(MY_RF24_CHANNEL);
|
||||||
rf24.setPALevel(_paLevel);
|
_rf24.setPALevel(_paLevel);
|
||||||
rf24.setDataRate(MY_RF24_DATARATE);
|
_rf24.setDataRate(MY_RF24_DATARATE);
|
||||||
rf24.setRetries(5,15);
|
_rf24.setRetries(5,15);
|
||||||
rf24.setCRCLength(RF24_CRC_16);
|
_rf24.setCRCLength(RF24_CRC_16);
|
||||||
rf24.enableDynamicPayloads();
|
_rf24.enableDynamicPayloads();
|
||||||
|
|
||||||
// All nodes listen to broadcast pipe (for FIND_PARENT_RESPONSE messages)
|
// All nodes listen to broadcast pipe (for FIND_PARENT_RESPONSE messages)
|
||||||
rf24.openReadingPipe(BROADCAST_PIPE, TO_ADDR(BROADCAST_ADDRESS));
|
_rf24.openReadingPipe(BROADCAST_PIPE, TO_ADDR(BROADCAST_ADDRESS));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyTransportNRF24::setAddress(uint8_t address) {
|
void transportSetAddress(uint8_t address) {
|
||||||
_address = address;
|
_address = address;
|
||||||
rf24.openReadingPipe(WRITE_PIPE, TO_ADDR(address));
|
_rf24.openReadingPipe(WRITE_PIPE, TO_ADDR(address));
|
||||||
rf24.openReadingPipe(CURRENT_NODE_PIPE, TO_ADDR(address));
|
_rf24.openReadingPipe(CURRENT_NODE_PIPE, TO_ADDR(address));
|
||||||
rf24.startListening();
|
_rf24.startListening();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t MyTransportNRF24::getAddress() {
|
uint8_t transportGetAddress() {
|
||||||
return _address;
|
return _address;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MyTransportNRF24::send(uint8_t to, const void* data, uint8_t len) {
|
bool transportSend(uint8_t to, const void* data, uint8_t len) {
|
||||||
// Make sure radio has powered up
|
// Make sure radio has powered up
|
||||||
rf24.powerUp();
|
_rf24.powerUp();
|
||||||
rf24.stopListening();
|
_rf24.stopListening();
|
||||||
rf24.openWritingPipe(TO_ADDR(to));
|
_rf24.openWritingPipe(TO_ADDR(to));
|
||||||
bool ok = rf24.write(data, len, to == BROADCAST_ADDRESS);
|
bool ok = _rf24.write(data, len, to == BROADCAST_ADDRESS);
|
||||||
rf24.startListening();
|
_rf24.startListening();
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MyTransportNRF24::available(uint8_t *to) {
|
bool transportAvailable(uint8_t *to) {
|
||||||
uint8_t pipe = 255;
|
uint8_t pipe = 255;
|
||||||
boolean avail = rf24.available(&pipe);
|
boolean avail = _rf24.available(&pipe);
|
||||||
(void)avail; //until somebody makes use of 'avail'
|
(void)avail; //until somebody makes use of 'avail'
|
||||||
if (pipe == CURRENT_NODE_PIPE)
|
if (pipe == CURRENT_NODE_PIPE)
|
||||||
*to = _address;
|
*to = _address;
|
||||||
else if (pipe == BROADCAST_PIPE)
|
else if (pipe == BROADCAST_PIPE)
|
||||||
*to = BROADCAST_ADDRESS;
|
*to = BROADCAST_ADDRESS;
|
||||||
return (rf24.available() && pipe < 6);
|
return (_rf24.available() && pipe < 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t MyTransportNRF24::receive(void* data) {
|
uint8_t transportReceive(void* data) {
|
||||||
uint8_t len = rf24.getDynamicPayloadSize();
|
uint8_t len = _rf24.getDynamicPayloadSize();
|
||||||
rf24.read(data, len);
|
_rf24.read(data, len);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyTransportNRF24::powerDown() {
|
void transportPowerDown() {
|
||||||
rf24.powerDown();
|
_rf24.powerDown();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,21 +32,12 @@
|
|||||||
#define CURRENT_NODE_PIPE ((uint8_t)1)
|
#define CURRENT_NODE_PIPE ((uint8_t)1)
|
||||||
#define BROADCAST_PIPE ((uint8_t)2)
|
#define BROADCAST_PIPE ((uint8_t)2)
|
||||||
|
|
||||||
class MyTransportNRF24 : public MyTransport
|
bool transportInit();
|
||||||
{
|
void transportSetAddress(uint8_t address);
|
||||||
public:
|
uint8_t transportGetAddress();
|
||||||
MyTransportNRF24();
|
bool transportSend(uint8_t to, const void* data, uint8_t len);
|
||||||
bool init();
|
bool transportAvailable(uint8_t *to);
|
||||||
void setAddress(uint8_t address);
|
uint8_t transportReceive(void* data);
|
||||||
uint8_t getAddress();
|
void transportPowerDown();
|
||||||
bool send(uint8_t to, const void* data, uint8_t len);
|
|
||||||
bool available(uint8_t *to);
|
|
||||||
uint8_t receive(void* data);
|
|
||||||
void powerDown();
|
|
||||||
private:
|
|
||||||
RF24 rf24;
|
|
||||||
uint8_t _address;
|
|
||||||
uint8_t _paLevel;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -20,52 +20,49 @@
|
|||||||
#include "MyTransport.h"
|
#include "MyTransport.h"
|
||||||
#include "MyTransportRFM69.h"
|
#include "MyTransportRFM69.h"
|
||||||
|
|
||||||
MyTransportRFM69::MyTransportRFM69()
|
RFM69 _radio(MY_RF69_SPI_CS, MY_RF69_IRQ_PIN, MY_IS_RFM69HW, MY_RF69_IRQ_NUM);
|
||||||
:
|
uint8_t _address;
|
||||||
MyTransport(),
|
|
||||||
radio(MY_RF69_SPI_CS, MY_RF69_IRQ_PIN, MY_IS_RFM69HW, MY_RF69_IRQ_NUM)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MyTransportRFM69::init() {
|
|
||||||
|
bool transportInit() {
|
||||||
// Start up the radio library (_address will be set later by the MySensors library)
|
// Start up the radio library (_address will be set later by the MySensors library)
|
||||||
radio.initialize(MY_RFM69_FREQUENCY, _address, MY_RFM69_NETWORKID);
|
_radio.initialize(MY_RFM69_FREQUENCY, _address, MY_RFM69_NETWORKID);
|
||||||
#ifdef MY_RFM69_ENABLE_ENCRYPTION
|
#ifdef MY_RFM69_ENABLE_ENCRYPTION
|
||||||
radio.encrypt(RFM69_ENCRYPTKEY);
|
_radio.encrypt(RFM69_ENCRYPTKEY);
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyTransportRFM69::setAddress(uint8_t address) {
|
void transportSetAddress(uint8_t address) {
|
||||||
_address = address;
|
_address = address;
|
||||||
radio.setAddress(address);
|
_radio.setAddress(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t MyTransportRFM69::getAddress() {
|
uint8_t transportGetAddress() {
|
||||||
return _address;
|
return _address;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MyTransportRFM69::send(uint8_t to, const void* data, uint8_t len) {
|
bool transportSend(uint8_t to, const void* data, uint8_t len) {
|
||||||
return radio.sendWithRetry(to,data,len);
|
return _radio.sendWithRetry(to,data,len);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MyTransportRFM69::available(uint8_t *to) {
|
bool transportAvailable(uint8_t *to) {
|
||||||
if (radio.TARGETID == BROADCAST_ADDRESS)
|
if (_radio.TARGETID == BROADCAST_ADDRESS)
|
||||||
*to = BROADCAST_ADDRESS;
|
*to = BROADCAST_ADDRESS;
|
||||||
else
|
else
|
||||||
*to = _address;
|
*to = _address;
|
||||||
return radio.receiveDone();
|
return _radio.receiveDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t MyTransportRFM69::receive(void* data) {
|
uint8_t transportReceive(void* data) {
|
||||||
memcpy(data,(const void *)radio.DATA, radio.DATALEN);
|
memcpy(data,(const void *)_radio.DATA, _radio.DATALEN);
|
||||||
// Send ack back if this message wasn't a broadcast
|
// Send ack back if this message wasn't a broadcast
|
||||||
if (radio.TARGETID != RF69_BROADCAST_ADDR)
|
if (_radio.TARGETID != RF69_BROADCAST_ADDR)
|
||||||
radio.ACKRequested();
|
_radio.ACKRequested();
|
||||||
radio.sendACK();
|
_radio.sendACK();
|
||||||
return radio.DATALEN;
|
return _radio.DATALEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyTransportRFM69::powerDown() {
|
void transportPowerDown() {
|
||||||
radio.sleep();
|
_radio.sleep();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,20 +27,12 @@
|
|||||||
#include "drivers/SPI/SPI.h"
|
#include "drivers/SPI/SPI.h"
|
||||||
|
|
||||||
|
|
||||||
class MyTransportRFM69 : public MyTransport
|
bool transportInit();
|
||||||
{
|
void transportSetAddress(uint8_t address);
|
||||||
public:
|
uint8_t transportGetAddress();
|
||||||
MyTransportRFM69();
|
bool transportSend(uint8_t to, const void* data, uint8_t len);
|
||||||
bool init();
|
bool transportAvailable(uint8_t *to);
|
||||||
void setAddress(uint8_t address);
|
uint8_t transportReceive(void* data);
|
||||||
uint8_t getAddress();
|
void transportPowerDown();
|
||||||
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
|
#endif
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user