Skip to content
Permalink
Browse files

Custom transport example

  • Loading branch information...
marceloaqno committed Feb 12, 2018
1 parent 6794c72 commit 696d0d3993d88b2dc4565db6cb12f57a461372ad
Showing with 130 additions and 6 deletions.
  1. +1 −1 MySensors.h
  2. +129 −5 examples/RelayActuator/RelayActuator.ino
@@ -259,7 +259,7 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
#endif

// TRANSPORT INCLUDES
#if defined(MY_RADIO_RF24) || defined(MY_RADIO_NRF5_ESB) || defined(MY_RADIO_RFM69) || defined(MY_RADIO_RFM95) || defined(MY_RS485)
#ifdef MY_SENSOR_NETWORK
#include "hal/transport/MyTransportHAL.h"
#include "core/MyTransport.h"

@@ -27,14 +27,14 @@
* http://www.mysensors.org/build/relay
*/

#include <SPI.h>
#include <Ethernet.h>

// Enable debug prints to serial monitor
#define MY_DEBUG

// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_NRF5_ESB
//#define MY_RADIO_RFM69
//#define MY_RADIO_RFM95
// For the custom transport
#define MY_SENSOR_NETWORK

// Enable repeater functionality for this node
#define MY_REPEATER_FEATURE
@@ -46,6 +46,11 @@
#define RELAY_ON 1 // GPIO value to write to turn on attached relay
#define RELAY_OFF 0 // GPIO value to write to turn off attached relay

EthernetClient client;

unsigned char nodeId;
MyMessage msg;
uint8_t data_available = 0;

void before()
{
@@ -95,3 +100,122 @@ void receive(const MyMessage &message)
}
}

bool transportSend(const uint8_t to, const void* data, const uint8_t len, const bool noACK)
{
if (client.connected()) {
client.write((uint8_t *)data, len);
}
}

bool transportInit(void)
{
// TODO
}

void transportSetAddress(const uint8_t address)
{
nodeId = address;
}

uint8_t transportGetAddress(void)
{
return nodeId;
}

bool transportAvailable(void)
{
uint8_t *ptr = (uint8_t *)&msg.last;
data_available = 0;

if (!client.connected()) {
client.stop();
// TODO: reconnect
} else {
// Check new packets
while (client.available()) {
*ptr++ = client.read();
data_available++;
}
}

return data_available;
}

uint8_t transportReceive(void* data)
{
uint8_t bytes = data_available;

memcpy(data, (void *)&msg.last, bytes);
data_available = 0;

return bytes;
}

bool transportSanityCheck(void)
{
// not implemented yet
return true;
}

void transportPowerDown(void)
{
// Nothing to shut down here
}

void transportPowerUp(void)
{
// Nothing to power up here
}

void transportSleep(void)
{
// not implemented
}

void transportStandBy(void)
{
// not implemented
}

int16_t transportGetSendingRSSI(void)
{
// not implemented
return INVALID_RSSI;
}

int16_t transportGetReceivingRSSI(void)
{
// not implemented
return INVALID_RSSI;
}

int16_t transportGetSendingSNR(void)
{
// not implemented
return INVALID_SNR;
}

int16_t transportGetReceivingSNR(void)
{
// not implemented
return INVALID_SNR;
}

int16_t transportGetTxPowerPercent(void)
{
// not implemented
return static_cast<int16_t>(100);
}

int16_t transportGetTxPowerLevel(void)
{
// not implemented
return static_cast<int16_t>(100);
}

bool transportSetTxPowerPercent(const uint8_t powerPercent)
{
// not possbile
(void)powerPercent;
return false;
}

0 comments on commit 696d0d3

Please sign in to comment.
You can’t perform that action at this time.