Clean up Ethernet defines a bit

Setting MY_CONTROLLER_IP_ADDRESS turns on client mode.
Setting MY_IP_ADDRESS turns off DHCP mode
This commit is contained in:
Henrik Ekblad
2015-09-13 18:26:18 +02:00
parent 050782e1e6
commit 76f208abe7
3 changed files with 15 additions and 17 deletions
+10 -7
View File
@@ -26,7 +26,7 @@
#include "MyConfig.h" #include "MyConfig.h"
#if defined(MY_GATEWAY_SERIAL) || defined(MY_GATEWAY_W5100_CLIENT) || defined(MY_GATEWAY_W5100_SERVER) #if defined(MY_GATEWAY_SERIAL) || defined(MY_GATEWAY_W5100)
#define MY_GATEWAY_FEATURE #define MY_GATEWAY_FEATURE
#define MY_NODE_TYPE "gateway" #define MY_NODE_TYPE "gateway"
#elif defined(MY_REPEATER_FEATURE) #elif defined(MY_REPEATER_FEATURE)
@@ -102,7 +102,7 @@
// We assume that a gateway having a radio also should act as repeater // We assume that a gateway having a radio also should act as repeater
#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)
#include "drivers/AVR/Ethernet_W5100/utility/socket.cpp" #include "drivers/AVR/Ethernet_W5100/utility/socket.cpp"
#include "drivers/AVR/Ethernet_W5100/utility/w5100.cpp" #include "drivers/AVR/Ethernet_W5100/utility/w5100.cpp"
#include "drivers/AVR/Ethernet_W5100/DNS.cpp" #include "drivers/AVR/Ethernet_W5100/DNS.cpp"
@@ -110,19 +110,22 @@
#include "drivers/AVR/Ethernet_W5100/EthernetUdp.cpp" #include "drivers/AVR/Ethernet_W5100/EthernetUdp.cpp"
#include "drivers/AVR/Ethernet_W5100/IPAddress.cpp" #include "drivers/AVR/Ethernet_W5100/IPAddress.cpp"
#if defined(MY_CONTROLLER_IP_ADDRESS)
#define MY_GATEWAY_CLIENT_MODE
#endif
#if !defined(MY_PORT) #if !defined(MY_PORT)
#error You must define MY_PORT #error You must define MY_PORT (cotroller or gatway port to open)
#endif #endif
#if !defined(USE_UDP) #if !defined(USE_UDP)
#include "drivers/AVR/Ethernet_W5100/EthernetServer.cpp" #include "drivers/AVR/Ethernet_W5100/EthernetServer.cpp"
#endif #endif
#if defined(MY_GATEWAY_W5100_CLIENT) && !defined(MY_CONTROLLER_IP_ADDRESS)
#error You must define MY_CONTROLLER_IP_ADDRESS when acting as client
#endif
#if defined(MY_GATEWAY_W5100_CLIENT) #if defined(MY_GATEWAY_CLIENT_MODE)
#include "drivers/AVR/Ethernet_W5100/EthernetClient.cpp" #include "drivers/AVR/Ethernet_W5100/EthernetClient.cpp"
#include "core/MyGatewayTransportEthernet.cpp" #include "core/MyGatewayTransportEthernet.cpp"
#else
// What do we do here?
#endif #endif
#elif defined(MY_GATEWAY_SERIAL) #elif defined(MY_GATEWAY_SERIAL)
#include "core/MyGatewayTransportSerial.cpp" #include "core/MyGatewayTransportSerial.cpp"
@@ -66,13 +66,13 @@ bool gatewayTransportSend(MyMessage &message)
else { else {
_ethernetMsg = protocolFormat(message); _ethernetMsg = protocolFormat(message);
#ifdef MY_USE_UDP #ifdef MY_USE_UDP
_ethernetServer.beginPacket(_ethernetControllerIP, MY_CONTROLLER_PORT); _ethernetServer.beginPacket(_ethernetControllerIP, MY_PORT);
_ethernetServer.write(_ethernetMsg, strlen(_ethernetMsg)); _ethernetServer.write(_ethernetMsg, strlen(_ethernetMsg));
// returns 1 if the packet was sent successfully // returns 1 if the packet was sent successfully
return _ethernetServer.endPacket(); return _ethernetServer.endPacket();
#else #else
EthernetClient client; EthernetClient client;
if (client.connect(_ethernetControllerIP, MY_CONTROLLER_PORT)) { if (client.connect(_ethernetControllerIP, MY_PORT)) {
client.write(_ethernetMsg, strlen(_ethernetMsg)); client.write(_ethernetMsg, strlen(_ethernetMsg));
client.stop(); client.stop();
return true; return true;
@@ -63,10 +63,8 @@
#define MY_RADIO_NRF24 #define MY_RADIO_NRF24
// W5100 Ethernet in client mode (node opens conmection to controller) // W5100 Ethernet gateway
#define MY_GATEWAY_W5100_CLIENT #define MY_GATEWAY_W5100
// W5100 Ethernet in client mode (controller opens conmection to node)
//#define MY_GATEWAY_W5100_SERVER
// Set default gateway protocol (http://www.mysensors.org/download/serial_api_15) // Set default gateway protocol (http://www.mysensors.org/download/serial_api_15)
#define MY_GATEWAY_PROTOCOL_DEFAULT #define MY_GATEWAY_PROTOCOL_DEFAULT
@@ -88,10 +86,8 @@
// The port to keep open on node server mode / or port to contact in client mode // The port to keep open on node server mode / or port to contact in client mode
#define MY_PORT 5003 #define MY_PORT 5003
// Controller ip address (client mode) // Controller ip address (enables client mode). Undefine this to act as sever.
#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 254 #define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 254
// The port you want to contact on controller (client mode)
#define MY_CONTROLLER_PORT 5003
// The MAC address can be anything you want but should be unique on your network. // The MAC address can be anything you want but should be unique on your network.
// Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use. // Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use.
@@ -124,7 +120,6 @@
void setup() void setup()
{ {
dataCallback();
} }
void loop() { void loop() {