Include .h instead of .cpp when possible
* Move implementation code from Arduino.h
This commit is contained in:
@@ -12,7 +12,7 @@ CONFIG_FILE=Makefile.inc
|
|||||||
include $(CONFIG_FILE)
|
include $(CONFIG_FILE)
|
||||||
|
|
||||||
GATEWAY=examples_RPi/MySGateway
|
GATEWAY=examples_RPi/MySGateway
|
||||||
GATEWAY_SOURCES=examples_RPi/MySGateway.cpp
|
GATEWAY_SOURCES=$(wildcard drivers/Linux/*.cpp) examples_RPi/MySGateway.cpp
|
||||||
GATEWAY_OBJECTS=$(patsubst %.cpp,%.o,$(GATEWAY_SOURCES))
|
GATEWAY_OBJECTS=$(patsubst %.cpp,%.o,$(GATEWAY_SOURCES))
|
||||||
DEPS+=$(patsubst %.cpp,%.d,$(GATEWAY_SOURCES))
|
DEPS+=$(patsubst %.cpp,%.d,$(GATEWAY_SOURCES))
|
||||||
|
|
||||||
|
|||||||
+6
-6
@@ -222,9 +222,9 @@
|
|||||||
#include "core/MyProtocolMySensors.cpp"
|
#include "core/MyProtocolMySensors.cpp"
|
||||||
|
|
||||||
#if defined(MY_GATEWAY_LINUX)
|
#if defined(MY_GATEWAY_LINUX)
|
||||||
#include "drivers/Linux/EthernetClient.cpp"
|
#include "drivers/Linux/EthernetClient.h"
|
||||||
#include "drivers/Linux/EthernetServer.cpp"
|
#include "drivers/Linux/EthernetServer.h"
|
||||||
#include "drivers/Linux/IPAddress.cpp"
|
#include "drivers/Linux/IPAddress.h"
|
||||||
#endif
|
#endif
|
||||||
#include "drivers/PubSubClient/PubSubClient.cpp"
|
#include "drivers/PubSubClient/PubSubClient.cpp"
|
||||||
#include "core/MyGatewayTransportMQTTClient.cpp"
|
#include "core/MyGatewayTransportMQTTClient.cpp"
|
||||||
@@ -250,9 +250,9 @@
|
|||||||
#include "core/MyGatewayTransportEthernet.cpp"
|
#include "core/MyGatewayTransportEthernet.cpp"
|
||||||
#elif defined(MY_GATEWAY_LINUX)
|
#elif defined(MY_GATEWAY_LINUX)
|
||||||
// GATEWAY - Generic Linux (RaspberryPi, BBB, ...)
|
// GATEWAY - Generic Linux (RaspberryPi, BBB, ...)
|
||||||
#include "drivers/Linux/EthernetClient.cpp"
|
#include "drivers/Linux/EthernetClient.h"
|
||||||
#include "drivers/Linux/EthernetServer.cpp"
|
#include "drivers/Linux/EthernetServer.h"
|
||||||
#include "drivers/Linux/IPAddress.cpp"
|
#include "drivers/Linux/IPAddress.h"
|
||||||
#include "core/MyGatewayTransportEthernet.cpp"
|
#include "core/MyGatewayTransportEthernet.cpp"
|
||||||
#elif defined(MY_GATEWAY_W5100)
|
#elif defined(MY_GATEWAY_W5100)
|
||||||
// GATEWAY - W5100
|
// GATEWAY - W5100
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ typedef struct
|
|||||||
|
|
||||||
#if defined(MY_USE_UDP)
|
#if defined(MY_USE_UDP)
|
||||||
EthernetUDP _ethernetServer;
|
EthernetUDP _ethernetServer;
|
||||||
|
#elif defined(MY_GATEWAY_LINUX)
|
||||||
|
EthernetServer _ethernetServer(_ethernetGatewayPort, MY_GATEWAY_MAX_CLIENTS);
|
||||||
#else
|
#else
|
||||||
EthernetServer _ethernetServer(_ethernetGatewayPort);
|
EthernetServer _ethernetServer(_ethernetGatewayPort);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+6
-174
@@ -2,6 +2,7 @@
|
|||||||
#define Arduino_h
|
#define Arduino_h
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@@ -45,180 +46,11 @@ void yield(void);
|
|||||||
typedef bool boolean;
|
typedef bool boolean;
|
||||||
typedef uint8_t byte;
|
typedef uint8_t byte;
|
||||||
|
|
||||||
/**
|
char *itoa(int value, char* result, int base);
|
||||||
* C++ version 0.4 char* style "itoa":
|
char *ltoa(long value, char* result, int base);
|
||||||
* Written by Lukás Chmela
|
char *ultoa(long num, char *str, int radix);
|
||||||
* Released under GPLv3.
|
char *utoa(int num, char *str, int radix);
|
||||||
*/
|
char *dtostrf(float f, int width, int decimals, char *result);
|
||||||
char *itoa(int value, char* result, int base) {
|
|
||||||
// check that the base if valid
|
|
||||||
if (base < 2 || base > 36) { *result = '\0'; return result; }
|
|
||||||
|
|
||||||
char* ptr = result, *ptr1 = result, tmp_char;
|
|
||||||
int tmp_value;
|
|
||||||
|
|
||||||
do {
|
|
||||||
tmp_value = value;
|
|
||||||
value /= base;
|
|
||||||
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)];
|
|
||||||
} while ( value );
|
|
||||||
|
|
||||||
// Apply negative sign
|
|
||||||
// Apply negative sign
|
|
||||||
if (tmp_value < 0) *ptr++ = '-';
|
|
||||||
*ptr-- = '\0';
|
|
||||||
while(ptr1 < ptr) {
|
|
||||||
tmp_char = *ptr;
|
|
||||||
*ptr--= *ptr1;
|
|
||||||
*ptr1++ = tmp_char;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* C++ version 0.4 char* style "itoa":
|
|
||||||
* Written by Lukás Chmela
|
|
||||||
* Released under GPLv3.
|
|
||||||
*/
|
|
||||||
char *ltoa(long value, char* result, int base) {
|
|
||||||
// check that the base if valid
|
|
||||||
if (base < 2 || base > 36) { *result = '\0'; return result; }
|
|
||||||
|
|
||||||
char* ptr = result, *ptr1 = result, tmp_char;
|
|
||||||
long tmp_value;
|
|
||||||
|
|
||||||
do {
|
|
||||||
tmp_value = value;
|
|
||||||
value /= base;
|
|
||||||
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)];
|
|
||||||
} while ( value );
|
|
||||||
|
|
||||||
// Apply negative sign
|
|
||||||
if (tmp_value < 0) *ptr++ = '-';
|
|
||||||
*ptr-- = '\0';
|
|
||||||
while(ptr1 < ptr) {
|
|
||||||
tmp_char = *ptr;
|
|
||||||
*ptr--= *ptr1;
|
|
||||||
*ptr1++ = tmp_char;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ultoa(long num, char *str, int radix)
|
|
||||||
{
|
|
||||||
unsigned long value;
|
|
||||||
char *sp = str;
|
|
||||||
char *sp2;
|
|
||||||
|
|
||||||
value = num;
|
|
||||||
|
|
||||||
/* Store sign at start of buffer for negative base-10 values */
|
|
||||||
if (10 == radix && 0 > num) {
|
|
||||||
*sp++ = '-';
|
|
||||||
value = -num;
|
|
||||||
}
|
|
||||||
|
|
||||||
sp2 = sp;
|
|
||||||
|
|
||||||
do {
|
|
||||||
char rem = value % radix;
|
|
||||||
value /= radix;
|
|
||||||
if (10 > rem) {
|
|
||||||
*sp++ = '0' + rem;
|
|
||||||
} else {
|
|
||||||
*sp++ = 'A' + rem - 10;
|
|
||||||
}
|
|
||||||
} while (0 < value);
|
|
||||||
|
|
||||||
/* Mark end of string */
|
|
||||||
*sp-- = 0;
|
|
||||||
|
|
||||||
/* Reverse string contents (excluding sign) in place */
|
|
||||||
while (sp2 < sp) {
|
|
||||||
char tmp = *sp2;
|
|
||||||
*sp2++ = *sp;
|
|
||||||
*sp-- = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copyright (c) 2012, Peter A. Bigot <bigotp@acm.org>
|
|
||||||
*
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* * Neither the name of the software nor the names of its contributors may be
|
|
||||||
* used to endorse or promote products derived from this software without
|
|
||||||
* specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
||||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
char *utoa(int num, char *str, int radix)
|
|
||||||
{
|
|
||||||
unsigned int value;
|
|
||||||
char *sp = str;
|
|
||||||
char *sp2;
|
|
||||||
|
|
||||||
value = num;
|
|
||||||
|
|
||||||
/* Store sign at start of buffer for negative base-10 values */
|
|
||||||
if (10 == radix && 0 > num) {
|
|
||||||
*sp++ = '-';
|
|
||||||
value = -num;
|
|
||||||
}
|
|
||||||
|
|
||||||
sp2 = sp;
|
|
||||||
|
|
||||||
do {
|
|
||||||
char rem = value % radix;
|
|
||||||
value /= radix;
|
|
||||||
if (10 > rem) {
|
|
||||||
*sp++ = '0' + rem;
|
|
||||||
} else {
|
|
||||||
*sp++ = 'A' + rem - 10;
|
|
||||||
}
|
|
||||||
} while (0 < value);
|
|
||||||
|
|
||||||
/* Mark end of string */
|
|
||||||
*sp-- = 0;
|
|
||||||
|
|
||||||
/* Reverse string contents (excluding sign) in place */
|
|
||||||
while (sp2 < sp) {
|
|
||||||
char tmp = *sp2;
|
|
||||||
*sp2++ = *sp;
|
|
||||||
*sp-- = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *dtostrf(float f, int width, int decimals, char *result)
|
|
||||||
{
|
|
||||||
sprintf(result,"%*.*f", width, decimals, f);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,25 @@
|
|||||||
/*
|
/*
|
||||||
* The MySensors Arduino library handles the wireless radio link and protocol
|
* The MySensors Arduino library handles the wireless radio link and protocol
|
||||||
* between your home built sensors/actuators and HA controller of choice.
|
* between your home built sensors/actuators and HA controller of choice.
|
||||||
* The sensors forms a self healing radio network with optional repeaters. Each
|
* 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
|
* 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 Marcelo Aquino <marceloaqno@gmail.org>
|
* Created by Marcelo Aquino <marceloaqno@gmail.org>
|
||||||
* Copyright (C) 2016 Marcelo Aquino
|
* Copyright (C) 2016 Marcelo Aquino
|
||||||
* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
|
* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
|
||||||
*
|
*
|
||||||
* Documentation: http://www.mysensors.org
|
* Documentation: http://www.mysensors.org
|
||||||
* Support Forum: http://forum.mysensors.org
|
* Support Forum: http://forum.mysensors.org
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* 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.
|
||||||
*
|
*
|
||||||
* Based on Arduino ethernet library, Copyright (c) 2010 Arduino LLC. All right reserved.
|
* Based on Arduino ethernet library, Copyright (c) 2010 Arduino LLC. All right reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
@@ -249,6 +250,6 @@ bool EthernetClient::operator==(const EthernetClient& rhs) {
|
|||||||
return _sock == rhs._sock && _sock != -1 && rhs._sock != -1;
|
return _sock == rhs._sock && _sock != -1 && rhs._sock != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t EthernetClient::getSocketNumber() {
|
int EthernetClient::getSocketNumber() {
|
||||||
return _sock;
|
return _sock;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,26 @@
|
|||||||
/*
|
/*
|
||||||
* The MySensors Arduino library handles the wireless radio link and protocol
|
* The MySensors Arduino library handles the wireless radio link and protocol
|
||||||
* between your home built sensors/actuators and HA controller of choice.
|
* between your home built sensors/actuators and HA controller of choice.
|
||||||
* The sensors forms a self healing radio network with optional repeaters. Each
|
* 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
|
* 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 Marcelo Aquino <marceloaqno@gmail.org>
|
* Created by Marcelo Aquino <marceloaqno@gmail.org>
|
||||||
* Copyright (C) 2016 Marcelo Aquino
|
* Copyright (C) 2016 Marcelo Aquino
|
||||||
* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
|
* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
|
||||||
*
|
*
|
||||||
* Documentation: http://www.mysensors.org
|
* Documentation: http://www.mysensors.org
|
||||||
* Support Forum: http://forum.mysensors.org
|
* Support Forum: http://forum.mysensors.org
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* 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.
|
||||||
*
|
*
|
||||||
* Based on Arduino ethernet library, Copyright (c) 2010 Arduino LLC. All right reserved.
|
* Based on Arduino ethernet library, Copyright (c) 2010 Arduino LLC. All right reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef ethernetclient_h
|
#ifndef EthernetClient_h
|
||||||
#define ethernetclient_h
|
#define EthernetClient_h
|
||||||
|
|
||||||
#include "Client.h"
|
#include "Client.h"
|
||||||
#include "IPAddress.h"
|
#include "IPAddress.h"
|
||||||
@@ -69,7 +69,7 @@ public:
|
|||||||
virtual bool operator!=(const bool value) { return bool() != value; }
|
virtual bool operator!=(const bool value) { return bool() != value; }
|
||||||
virtual bool operator==(const EthernetClient&);
|
virtual bool operator==(const EthernetClient&);
|
||||||
virtual bool operator!=(const EthernetClient& rhs) { return !this->operator==(rhs); };
|
virtual bool operator!=(const EthernetClient& rhs) { return !this->operator==(rhs); };
|
||||||
uint8_t getSocketNumber();
|
int getSocketNumber();
|
||||||
|
|
||||||
friend class EthernetServer;
|
friend class EthernetServer;
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,25 @@
|
|||||||
/*
|
/*
|
||||||
* The MySensors Arduino library handles the wireless radio link and protocol
|
* The MySensors Arduino library handles the wireless radio link and protocol
|
||||||
* between your home built sensors/actuators and HA controller of choice.
|
* between your home built sensors/actuators and HA controller of choice.
|
||||||
* The sensors forms a self healing radio network with optional repeaters. Each
|
* 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
|
* 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 Marcelo Aquino <marceloaqno@gmail.org>
|
* Created by Marcelo Aquino <marceloaqno@gmail.org>
|
||||||
* Copyright (C) 2016 Marcelo Aquino
|
* Copyright (C) 2016 Marcelo Aquino
|
||||||
* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
|
* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
|
||||||
*
|
*
|
||||||
* Documentation: http://www.mysensors.org
|
* Documentation: http://www.mysensors.org
|
||||||
* Support Forum: http://forum.mysensors.org
|
* Support Forum: http://forum.mysensors.org
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* 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.
|
||||||
*
|
*
|
||||||
* Based on Arduino ethernet library, Copyright (c) 2010 Arduino LLC. All right reserved.
|
* Based on Arduino ethernet library, Copyright (c) 2010 Arduino LLC. All right reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
@@ -33,6 +34,7 @@ struct server_vars {
|
|||||||
struct IPAddress address;
|
struct IPAddress address;
|
||||||
std::list<int> *new_clients;
|
std::list<int> *new_clients;
|
||||||
std::vector<int> *clients;
|
std::vector<int> *clients;
|
||||||
|
uint16_t max_clients;
|
||||||
};
|
};
|
||||||
|
|
||||||
static pthread_mutex_t new_clients_mutex = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t new_clients_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
@@ -40,9 +42,9 @@ static pthread_mutex_t clients_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|||||||
|
|
||||||
void *incoming_connections(void *);
|
void *incoming_connections(void *);
|
||||||
|
|
||||||
EthernetServer::EthernetServer(uint16_t port) : port(port)
|
EthernetServer::EthernetServer(uint16_t port, uint16_t max_clients) : port(port), max_clients(max_clients)
|
||||||
{
|
{
|
||||||
clients.reserve(MY_GATEWAY_MAX_CLIENTS);
|
clients.reserve(max_clients);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EthernetServer::begin()
|
void EthernetServer::begin()
|
||||||
@@ -60,6 +62,7 @@ void EthernetServer::begin(IPAddress address)
|
|||||||
vars->address = address;
|
vars->address = address;
|
||||||
vars->new_clients = &new_clients;
|
vars->new_clients = &new_clients;
|
||||||
vars->clients = &clients;
|
vars->clients = &clients;
|
||||||
|
vars->max_clients = max_clients;
|
||||||
|
|
||||||
pthread_attr_init(&detached_attr);
|
pthread_attr_init(&detached_attr);
|
||||||
pthread_attr_setdetachstate(&detached_attr, PTHREAD_CREATE_DETACHED);
|
pthread_attr_setdetachstate(&detached_attr, PTHREAD_CREATE_DETACHED);
|
||||||
@@ -137,6 +140,7 @@ size_t EthernetServer::write(const char *str) {
|
|||||||
if (str == NULL) return 0;
|
if (str == NULL) return 0;
|
||||||
return write((const uint8_t *)str, strlen(str));
|
return write((const uint8_t *)str, strlen(str));
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t EthernetServer::write(const char *buffer, size_t size) {
|
size_t EthernetServer::write(const char *buffer, size_t size) {
|
||||||
return write((const uint8_t *)buffer, size);
|
return write((const uint8_t *)buffer, size);
|
||||||
}
|
}
|
||||||
@@ -221,7 +225,7 @@ void *incoming_connections(void* thread_arg)
|
|||||||
pthread_mutex_lock(&clients_mutex);
|
pthread_mutex_lock(&clients_mutex);
|
||||||
int connected_clients = vars->new_clients->size() + vars->clients->size();
|
int connected_clients = vars->new_clients->size() + vars->clients->size();
|
||||||
|
|
||||||
if (connected_clients == MY_GATEWAY_MAX_CLIENTS) {
|
if (connected_clients == vars->max_clients) {
|
||||||
pthread_mutex_unlock(&clients_mutex);
|
pthread_mutex_unlock(&clients_mutex);
|
||||||
pthread_mutex_unlock(&new_clients_mutex);
|
pthread_mutex_unlock(&new_clients_mutex);
|
||||||
ETHERNETSERVER_DEBUG("Max number of ethernet clients reached.");
|
ETHERNETSERVER_DEBUG("Max number of ethernet clients reached.");
|
||||||
|
|||||||
@@ -1,26 +1,26 @@
|
|||||||
/*
|
/*
|
||||||
* The MySensors Arduino library handles the wireless radio link and protocol
|
* The MySensors Arduino library handles the wireless radio link and protocol
|
||||||
* between your home built sensors/actuators and HA controller of choice.
|
* between your home built sensors/actuators and HA controller of choice.
|
||||||
* The sensors forms a self healing radio network with optional repeaters. Each
|
* 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
|
* 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 Marcelo Aquino <marceloaqno@gmail.org>
|
* Created by Marcelo Aquino <marceloaqno@gmail.org>
|
||||||
* Copyright (C) 2016 Marcelo Aquino
|
* Copyright (C) 2016 Marcelo Aquino
|
||||||
* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
|
* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
|
||||||
*
|
*
|
||||||
* Documentation: http://www.mysensors.org
|
* Documentation: http://www.mysensors.org
|
||||||
* Support Forum: http://forum.mysensors.org
|
* Support Forum: http://forum.mysensors.org
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* 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.
|
||||||
*
|
*
|
||||||
* Based on Arduino ethernet library, Copyright (c) 2010 Arduino LLC. All right reserved.
|
* Based on Arduino ethernet library, Copyright (c) 2010 Arduino LLC. All right reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef ethernetserver_h
|
#ifndef EthernetServer_h
|
||||||
#define ethernetserver_h
|
#define EthernetServer_h
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -31,6 +31,10 @@
|
|||||||
#define ETHERNETSERVER_BACKLOG 10
|
#define ETHERNETSERVER_BACKLOG 10
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef ETHERNETSERVER_MAX_CLIENTS
|
||||||
|
#define ETHERNETSERVER_MAX_CLIENTS ETHERNETSERVER_BACKLOG
|
||||||
|
#endif
|
||||||
|
|
||||||
// debug
|
// debug
|
||||||
#if defined(ETHERNETSERVER_VERBOSE)
|
#if defined(ETHERNETSERVER_VERBOSE)
|
||||||
#define ETHERNETSERVER_DEBUG(x,...) debug(x, ##__VA_ARGS__)
|
#define ETHERNETSERVER_DEBUG(x,...) debug(x, ##__VA_ARGS__)
|
||||||
@@ -46,9 +50,10 @@ private:
|
|||||||
uint16_t port;
|
uint16_t port;
|
||||||
std::list<int> new_clients;
|
std::list<int> new_clients;
|
||||||
std::vector<int> clients;
|
std::vector<int> clients;
|
||||||
|
uint16_t max_clients;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EthernetServer(uint16_t);
|
EthernetServer(uint16_t port, uint16_t max_clients = ETHERNETSERVER_MAX_CLIENTS);
|
||||||
virtual void begin();
|
virtual void begin();
|
||||||
void begin(IPAddress);
|
void begin(IPAddress);
|
||||||
void beginPacket(IPAddress, uint16_t);
|
void beginPacket(IPAddress, uint16_t);
|
||||||
|
|||||||
+20
-19
@@ -1,25 +1,26 @@
|
|||||||
/*
|
/*
|
||||||
IPAddress.cpp - Base class that provides IPAddress
|
* IPAddress.cpp - Base class that provides IPAddress
|
||||||
Copyright (c) 2011 Adrian McEwen. All right reserved.
|
* Copyright (c) 2011 Adrian McEwen. All right reserved.
|
||||||
|
*
|
||||||
This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
License as published by the Free Software Foundation; either
|
* License as published by the Free Software Foundation; either
|
||||||
version 2.1 of the License, or (at your option) any later version.
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
This library is distributed in the hope that it will be useful,
|
* This library is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
Lesser General Public License for more details.
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
You should have received a copy of the GNU Lesser General Public
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
License along with this library; if not, write to the Free Software
|
* License along with this library; if not, write to the Free Software
|
||||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
*
|
||||||
Modified by Marcelo Aquino <marceloaqno@gmail.org> for MySensors use
|
* Modified by Marcelo Aquino <marceloaqno@gmail.org> for MySensors use
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include "IPAddress.h"
|
#include "IPAddress.h"
|
||||||
|
|
||||||
|
|||||||
+19
-19
@@ -1,23 +1,23 @@
|
|||||||
/*
|
/*
|
||||||
IPAddress.h - Base class that provides IPAddress
|
* IPAddress.h - Base class that provides IPAddress
|
||||||
Copyright (c) 2011 Adrian McEwen. All right reserved.
|
* Copyright (c) 2011 Adrian McEwen. All right reserved.
|
||||||
|
*
|
||||||
This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
License as published by the Free Software Foundation; either
|
* License as published by the Free Software Foundation; either
|
||||||
version 2.1 of the License, or (at your option) any later version.
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
This library is distributed in the hope that it will be useful,
|
* This library is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
Lesser General Public License for more details.
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
You should have received a copy of the GNU Lesser General Public
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
License along with this library; if not, write to the Free Software
|
* License along with this library; if not, write to the Free Software
|
||||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
*
|
||||||
Modified by Marcelo Aquino <marceloaqno@gmail.org> for MySensors use
|
* Modified by Marcelo Aquino <marceloaqno@gmail.org> for MySensors use
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef IPAddress_h
|
#ifndef IPAddress_h
|
||||||
|
|||||||
@@ -0,0 +1,177 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include "Arduino.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* C++ version 0.4 char* style "itoa":
|
||||||
|
* Written by Lukás Chmela
|
||||||
|
* Released under GPLv3.
|
||||||
|
*/
|
||||||
|
char *itoa(int value, char* result, int base) {
|
||||||
|
// check that the base if valid
|
||||||
|
if (base < 2 || base > 36) { *result = '\0'; return result; }
|
||||||
|
|
||||||
|
char* ptr = result, *ptr1 = result, tmp_char;
|
||||||
|
int tmp_value;
|
||||||
|
|
||||||
|
do {
|
||||||
|
tmp_value = value;
|
||||||
|
value /= base;
|
||||||
|
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)];
|
||||||
|
} while ( value );
|
||||||
|
|
||||||
|
// Apply negative sign
|
||||||
|
// Apply negative sign
|
||||||
|
if (tmp_value < 0) *ptr++ = '-';
|
||||||
|
*ptr-- = '\0';
|
||||||
|
while(ptr1 < ptr) {
|
||||||
|
tmp_char = *ptr;
|
||||||
|
*ptr--= *ptr1;
|
||||||
|
*ptr1++ = tmp_char;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* C++ version 0.4 char* style "itoa":
|
||||||
|
* Written by Lukás Chmela
|
||||||
|
* Released under GPLv3.
|
||||||
|
*/
|
||||||
|
char *ltoa(long value, char* result, int base) {
|
||||||
|
// check that the base if valid
|
||||||
|
if (base < 2 || base > 36) { *result = '\0'; return result; }
|
||||||
|
|
||||||
|
char* ptr = result, *ptr1 = result, tmp_char;
|
||||||
|
long tmp_value;
|
||||||
|
|
||||||
|
do {
|
||||||
|
tmp_value = value;
|
||||||
|
value /= base;
|
||||||
|
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" [35 + (tmp_value - value * base)];
|
||||||
|
} while ( value );
|
||||||
|
|
||||||
|
// Apply negative sign
|
||||||
|
if (tmp_value < 0) *ptr++ = '-';
|
||||||
|
*ptr-- = '\0';
|
||||||
|
while(ptr1 < ptr) {
|
||||||
|
tmp_char = *ptr;
|
||||||
|
*ptr--= *ptr1;
|
||||||
|
*ptr1++ = tmp_char;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *ultoa(long num, char *str, int radix)
|
||||||
|
{
|
||||||
|
unsigned long value;
|
||||||
|
char *sp = str;
|
||||||
|
char *sp2;
|
||||||
|
|
||||||
|
value = num;
|
||||||
|
|
||||||
|
/* Store sign at start of buffer for negative base-10 values */
|
||||||
|
if (10 == radix && 0 > num) {
|
||||||
|
*sp++ = '-';
|
||||||
|
value = -num;
|
||||||
|
}
|
||||||
|
|
||||||
|
sp2 = sp;
|
||||||
|
|
||||||
|
do {
|
||||||
|
char rem = value % radix;
|
||||||
|
value /= radix;
|
||||||
|
if (10 > rem) {
|
||||||
|
*sp++ = '0' + rem;
|
||||||
|
} else {
|
||||||
|
*sp++ = 'A' + rem - 10;
|
||||||
|
}
|
||||||
|
} while (0 < value);
|
||||||
|
|
||||||
|
/* Mark end of string */
|
||||||
|
*sp-- = 0;
|
||||||
|
|
||||||
|
/* Reverse string contents (excluding sign) in place */
|
||||||
|
while (sp2 < sp) {
|
||||||
|
char tmp = *sp2;
|
||||||
|
*sp2++ = *sp;
|
||||||
|
*sp-- = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2012, Peter A. Bigot <bigotp@acm.org>
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* * Neither the name of the software nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software without
|
||||||
|
* specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
char *utoa(int num, char *str, int radix)
|
||||||
|
{
|
||||||
|
unsigned int value;
|
||||||
|
char *sp = str;
|
||||||
|
char *sp2;
|
||||||
|
|
||||||
|
value = num;
|
||||||
|
|
||||||
|
/* Store sign at start of buffer for negative base-10 values */
|
||||||
|
if (10 == radix && 0 > num) {
|
||||||
|
*sp++ = '-';
|
||||||
|
value = -num;
|
||||||
|
}
|
||||||
|
|
||||||
|
sp2 = sp;
|
||||||
|
|
||||||
|
do {
|
||||||
|
char rem = value % radix;
|
||||||
|
value /= radix;
|
||||||
|
if (10 > rem) {
|
||||||
|
*sp++ = '0' + rem;
|
||||||
|
} else {
|
||||||
|
*sp++ = 'A' + rem - 10;
|
||||||
|
}
|
||||||
|
} while (0 < value);
|
||||||
|
|
||||||
|
/* Mark end of string */
|
||||||
|
*sp-- = 0;
|
||||||
|
|
||||||
|
/* Reverse string contents (excluding sign) in place */
|
||||||
|
while (sp2 < sp) {
|
||||||
|
char tmp = *sp2;
|
||||||
|
*sp2++ = *sp;
|
||||||
|
*sp-- = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *dtostrf(float f, int width, int decimals, char *result)
|
||||||
|
{
|
||||||
|
sprintf(result,"%*.*f", width, decimals, f);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user