2020-10-22 19:25:20 +02:00
|
|
|
/*
|
2020-11-10 10:58:01 +01:00
|
|
|
* © 2020 Gregor Baues. All rights reserved.
|
2020-10-22 19:25:20 +02:00
|
|
|
*
|
2020-11-10 10:58:01 +01:00
|
|
|
* This is free software: you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* See the GNU General Public License for more details <https://www.gnu.org/licenses/>
|
2020-10-22 19:25:20 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef NetworkInterface_h
|
|
|
|
#define NetworkInterface_h
|
|
|
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
2020-10-27 09:52:06 +01:00
|
|
|
#include "NetworkConfig.h"
|
2020-10-22 19:25:20 +02:00
|
|
|
#include "HttpRequest.h"
|
|
|
|
|
|
|
|
typedef enum protocolType {
|
|
|
|
TCP,
|
2020-11-09 17:00:24 +01:00
|
|
|
UDPR, // UDP clashes with a class name in the network stack
|
2020-10-27 09:52:06 +01:00
|
|
|
MQTT
|
2020-10-22 19:25:20 +02:00
|
|
|
} protocolType;
|
|
|
|
|
|
|
|
typedef enum transportType {
|
|
|
|
WIFI, // using an AT (Version >= V1.7) command enabled ESP8266 not to be used in conjunction with the WifiInterface though! not tested for conflicts
|
|
|
|
ETHERNET // using the EthernetShield
|
2020-10-26 10:29:40 +01:00
|
|
|
} transportType;
|
2020-10-22 19:25:20 +02:00
|
|
|
|
|
|
|
using HttpCallback = void(*)(ParsedRequest *req, Client *client);
|
|
|
|
|
2020-10-27 09:52:06 +01:00
|
|
|
/**
|
|
|
|
* @brief Abstract parent class of the templated ( Ethernet or Wifi ) class
|
|
|
|
* Instances of Transports are hold through this in an array in DCCNetwork which describes and
|
|
|
|
* actually manages the available transports.
|
|
|
|
*/
|
|
|
|
struct AbstractTransport {
|
|
|
|
void loop(){};
|
|
|
|
virtual ~AbstractTransport(){};
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Core class holding and running the instantiated Transports
|
|
|
|
* initalized through the NetworkInterface. The number of transports is
|
|
|
|
* limited by MAX_INTERFACES
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class DCCNetwork {
|
|
|
|
private:
|
|
|
|
byte _tCounter = 0;
|
|
|
|
transportType _t[MAX_INTERFACES];
|
|
|
|
public:
|
|
|
|
AbstractTransport *transports[MAX_INTERFACES];
|
|
|
|
|
|
|
|
byte add(AbstractTransport* t, transportType _t);
|
|
|
|
void loop();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Main entry point and provider of callbacks. Sole responsibility is to create
|
|
|
|
* the transport endpoints and loop over them for processing
|
|
|
|
*
|
|
|
|
*/
|
2020-10-22 19:25:20 +02:00
|
|
|
class NetworkInterface
|
|
|
|
{
|
|
|
|
private:
|
2020-10-26 10:29:40 +01:00
|
|
|
HttpCallback httpCallback;
|
|
|
|
transportType t;
|
2020-10-22 19:25:20 +02:00
|
|
|
|
|
|
|
public:
|
2020-10-27 09:52:06 +01:00
|
|
|
|
2020-10-26 10:29:40 +01:00
|
|
|
void setHttpCallback(HttpCallback callback);
|
|
|
|
HttpCallback getHttpCallback();
|
|
|
|
void setup(transportType t, protocolType p, uint16_t port); // specific port nummber
|
|
|
|
void setup(transportType t, protocolType p); // uses default port number
|
|
|
|
void setup(transportType t); // defaults for protocol/port
|
2020-10-22 19:25:20 +02:00
|
|
|
|
2020-10-26 10:29:40 +01:00
|
|
|
void setup(); // defaults for all as above plus CABLE (i.e. using EthernetShield ) as default
|
2020-10-27 09:52:06 +01:00
|
|
|
static void loop();
|
2020-10-22 19:25:20 +02:00
|
|
|
|
|
|
|
NetworkInterface();
|
|
|
|
~NetworkInterface();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|