Compare commits
3 Commits
3e193233b4
...
5627ebde48
Author | SHA1 | Date | |
---|---|---|---|
|
5627ebde48 | ||
|
0c622c600b | ||
|
125a02c0e6 |
@ -16,6 +16,7 @@ void *CFGFileParser::parseFile()
|
|||||||
if(!_sdCardManager.isMounted()) return NULL;
|
if(!_sdCardManager.isMounted()) return NULL;
|
||||||
|
|
||||||
file = _sdCardManager.open(_resource);
|
file = _sdCardManager.open(_resource);
|
||||||
|
//We check if the file name is not NULL :-)
|
||||||
if(!file)
|
if(!file)
|
||||||
{
|
{
|
||||||
delete dictioRef;
|
delete dictioRef;
|
||||||
|
@ -46,7 +46,6 @@ CFGParameterValue::~CFGParameterValue()
|
|||||||
void CFGParameterValue::setValue(const char *value, bool isQuoted)
|
void CFGParameterValue::setValue(const char *value, bool isQuoted)
|
||||||
{
|
{
|
||||||
_quotedValue = isQuoted;
|
_quotedValue = isQuoted;
|
||||||
|
|
||||||
free(_value);_value = NULL;
|
free(_value);_value = NULL;
|
||||||
_value = (char *) malloc((strlen(value) * sizeof(char)) + 1); //+1 for the string terminating character
|
_value = (char *) malloc((strlen(value) * sizeof(char)) + 1); //+1 for the string terminating character
|
||||||
strcpy(_value, value);
|
strcpy(_value, value);
|
||||||
|
@ -19,6 +19,30 @@ _pcf(_boardConfig.getI2C_IOExpanderAddress(), Wire),
|
|||||||
_ioManager(_pcf),
|
_ioManager(_pcf),
|
||||||
_taskSchedulerManager(_rtcManager),
|
_taskSchedulerManager(_rtcManager),
|
||||||
_error(0)
|
_error(0)
|
||||||
|
{
|
||||||
|
initCommonConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
SAB::SAB(const BoardConfig boardConfig, const unsigned int webServerPort, const unsigned int ftpServerPort) : _boardConfig(boardConfig),
|
||||||
|
_sdCardManager(_boardConfig.getSPI_SDCard_cs(), _boardConfig.getSPISpeed()),
|
||||||
|
_display(_boardConfig.getScreenWidth(), _boardConfig.getScreenHeight(), &Wire),
|
||||||
|
_screenManager(_display, &_sdCardManager),
|
||||||
|
_rtc(),
|
||||||
|
_rtcManager(_rtc),
|
||||||
|
_connectivityManager(NULL),
|
||||||
|
//_webServerManager(webServerPort, &_sdCardManager),
|
||||||
|
_webServer(webServerPort, &_sdCardManager, 10),
|
||||||
|
_ftpServer(ftpServerPort, &_sdCardManager, "ESP8266", "12345678"),
|
||||||
|
_dbWSServer(81),
|
||||||
|
_pcf(_boardConfig.getI2C_IOExpanderAddress(), Wire),
|
||||||
|
_ioManager(_pcf),
|
||||||
|
_taskSchedulerManager(_rtcManager),
|
||||||
|
_error(0)
|
||||||
|
{
|
||||||
|
initCommonConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SAB::initCommonConfig()
|
||||||
{
|
{
|
||||||
//We set the gpio up
|
//We set the gpio up
|
||||||
initGPIO();
|
initGPIO();
|
||||||
@ -44,49 +68,11 @@ _error(0)
|
|||||||
if(!_pcf.begin()){_error |= IO_INIT_ERR;}
|
if(!_pcf.begin()){_error |= IO_INIT_ERR;}
|
||||||
|
|
||||||
_powerUpTime = _rtcManager.getDateTime();
|
_powerUpTime = _rtcManager.getDateTime();
|
||||||
_dbWSServer.begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
SAB::SAB(const BoardConfig boardConfig, const unsigned int webServerPort, const unsigned int ftpServerPort) : _boardConfig(boardConfig),
|
//We set the different servers :
|
||||||
_sdCardManager(_boardConfig.getSPI_SDCard_cs(), _boardConfig.getSPISpeed()),
|
|
||||||
_display(_boardConfig.getScreenWidth(), _boardConfig.getScreenHeight(), &Wire),
|
|
||||||
_screenManager(_display, &_sdCardManager),
|
|
||||||
_rtc(),
|
|
||||||
_rtcManager(_rtc),
|
|
||||||
_connectivityManager(NULL),
|
|
||||||
//_webServerManager(webServerPort, &_sdCardManager),
|
|
||||||
_webServer(webServerPort, &_sdCardManager, 10),
|
|
||||||
_ftpServer(ftpServerPort, &_sdCardManager, "ESP8266", "12345678"),
|
|
||||||
_dbWSServer(81),
|
|
||||||
_pcf(_boardConfig.getI2C_IOExpanderAddress(), Wire),
|
|
||||||
_ioManager(_pcf),
|
|
||||||
_taskSchedulerManager(_rtcManager),
|
|
||||||
_error(0)
|
|
||||||
{
|
|
||||||
//We set the gpio up
|
|
||||||
initGPIO();
|
|
||||||
Serial.begin(115200, SERIAL_8N1, SERIAL_TX_ONLY);
|
|
||||||
Serial.println();
|
|
||||||
delay(200);
|
|
||||||
//We initialize the pins for the I2C communication
|
|
||||||
Wire.begin(_boardConfig.getI2C_sda(), _boardConfig.getI2C_scl());
|
|
||||||
if(!_rtc.begin()) _error |= RTC_BEGIN_ERR;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SAB::_rtcManagerP = &_rtcManager;
|
|
||||||
}
|
|
||||||
if(!_display.begin(SSD1306_SWITCHCAPVCC, _boardConfig.getI2C_screenAddress())) _error |= DISP_BEGIN_ERR;
|
|
||||||
if(!_sdCardManager.mountSD()){ _error |= SDCARD_INIT_ERR; Serial.print("Failed to init SDCard : SPI_SPEED : "); Serial.print(8000000); Serial.print(" CS PIN : "); Serial.println(_boardConfig.getSPI_SDCard_cs());}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_sdCardManager.setTimeCallback(&(SAB::myTimeCallback));
|
|
||||||
}
|
|
||||||
_screenManager.init();
|
|
||||||
_connectivityManager = new ConnectivityManager(_sdCardManager);
|
|
||||||
if(!_pcf.begin()){_error |= IO_INIT_ERR;}
|
|
||||||
|
|
||||||
_powerUpTime = _rtcManager.getDateTime();
|
|
||||||
_dbWSServer.begin();
|
_dbWSServer.begin();
|
||||||
|
_webServer.enableTcpKeepAlive(15,5,5);
|
||||||
|
_ftpServer.enableTcpKeepAlive(15,5,5);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SAB::initGPIO()
|
void SAB::initGPIO()
|
||||||
|
@ -49,6 +49,7 @@ class SAB
|
|||||||
private:
|
private:
|
||||||
void initGPIO();
|
void initGPIO();
|
||||||
static time_t myTimeCallback();
|
static time_t myTimeCallback();
|
||||||
|
void initCommonConfig();
|
||||||
const BoardConfig _boardConfig;
|
const BoardConfig _boardConfig;
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include "List.h"
|
#include "List.h"
|
||||||
#include "TCPClient.h"
|
#include "TCPClient.h"
|
||||||
|
|
||||||
#define MAX_CLIENT -1
|
#define MAX_CLIENT 0
|
||||||
//#define DEBUG_TCPS
|
//#define DEBUG_TCPS
|
||||||
|
|
||||||
|
|
||||||
@ -62,6 +62,17 @@ class TCPServer
|
|||||||
_serverStarted = false;
|
_serverStarted = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void enableTCPKeepAlive(uint16_t timeBetween2KATransmitions = TCP_DEFAULT_KEEPALIVE_IDLE_SEC,
|
||||||
|
uint16_t timeBetweenFailedKARetransmissions = TCP_DEFAULT_KEEPALIVE_INTERVAL_SEC,
|
||||||
|
uint8_t retriesBeforeDrop = TCP_DEFAULT_KEEPALIVE_COUNT)
|
||||||
|
{
|
||||||
|
_TKAIdleSec = timeBetween2KATransmitions;
|
||||||
|
_TKAIntvSec = timeBetweenFailedKARetransmissions;
|
||||||
|
_TKACount = retriesBeforeDrop;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void disableTCPKeepAlive(){ _TKAIdleSec = 0;_TKAIntvSec = 0;_TKACount = 0; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual T* createNewClient(WiFiClient wc)
|
virtual T* createNewClient(WiFiClient wc)
|
||||||
@ -73,7 +84,7 @@ class TCPServer
|
|||||||
{
|
{
|
||||||
WiFiClient wc;
|
WiFiClient wc;
|
||||||
|
|
||||||
if(_maxClient == -1 || _maxClient > _clientList.count())
|
if(!_maxClient || _maxClient > _clientList.count())
|
||||||
{
|
{
|
||||||
wc = _wifiServer.available();
|
wc = _wifiServer.available();
|
||||||
}
|
}
|
||||||
@ -81,11 +92,15 @@ class TCPServer
|
|||||||
if(wc && wc.connected())
|
if(wc && wc.connected())
|
||||||
{
|
{
|
||||||
T *clientPointer = createNewClient(wc);
|
T *clientPointer = createNewClient(wc);
|
||||||
//Activate keepAlive
|
//We activate the TKA : (The check is internally done in the
|
||||||
(clientPointer->_client).keepAlive(15, 5, 5);
|
//ClientContext.h class : ie if one of the provided parameters is 0, then TKA is disabled)
|
||||||
|
(clientPointer->_client).keepAlive(_TKAIdleSec, _TKAIntvSec, _TKACount);
|
||||||
|
|
||||||
_clientList.addFirst(clientPointer);
|
_clientList.addFirst(clientPointer);
|
||||||
#ifdef DEBUG_TCPS
|
#ifdef DEBUG_TCPS
|
||||||
Serial.printf("TCPServer : New client accepted. Id : %u , Number of clients : %u, local port : %u, remote port : %u\n",clientPointer->_id, _clientList.count(),clientPointer->_client.localPort(),clientPointer->_client.remotePort());
|
Serial.printf("TCPServer : New client accepted. Id : %u , Number of clients : %u, local port : %u, remote port : %u\n",clientPointer->_id, _clientList.count(),clientPointer->_client.localPort(),clientPointer->_client.remotePort());
|
||||||
|
if(_TKAIdleSec && _TKAIntvSec && _TKACount)
|
||||||
|
Serial.printf("TCPKeepAlive enabled for client id : %u\n", clientPointer->_id);
|
||||||
#endif
|
#endif
|
||||||
greetClient(clientPointer);
|
greetClient(clientPointer);
|
||||||
}
|
}
|
||||||
@ -104,7 +119,7 @@ class TCPServer
|
|||||||
|
|
||||||
virtual void greetClient(T *client)
|
virtual void greetClient(T *client)
|
||||||
{
|
{
|
||||||
client->_client.printf_P(PSTR("Successfully connected at %lu !\r\nYour are client with id : %u\r\n"), millis(), client->_id);
|
client->_client.printf_P(PSTR("Successfully connected at %lu !\r\nYour are client with id : %u\r\n"), millis(), client->_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void getClientData()
|
virtual void getClientData()
|
||||||
@ -133,14 +148,14 @@ class TCPServer
|
|||||||
else if(!(_currentClient->_client).connected())
|
else if(!(_currentClient->_client).connected())
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_TCPS
|
#ifdef DEBUG_TCPS
|
||||||
Serial.print("TCPServer : Client disconnected and can be discarded : ");Serial.println(_currentClient->_id);
|
Serial.printf("TCPServer : Client disconnected and can be discarded : %u\n", _currentClient->_id);
|
||||||
#endif
|
#endif
|
||||||
_currentClient->_clientState = TCPClient::DISCARDED;
|
_currentClient->_clientState = TCPClient::DISCARDED;
|
||||||
}
|
}
|
||||||
else //Strange
|
else //Strange
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_TCPS
|
#ifdef DEBUG_TCPS
|
||||||
Serial.printf("Client status %u : %u and available : %u Is keepAlive enabled : %d\n", _currentClient->_id, (_currentClient->_client).status(), (_currentClient->_client).available(), (_currentClient->_client).isKeepAliveEnabled());
|
Serial.printf("Client(%u/%u) id : %u, with TCP status : %u and available : %u, Is keepAlive enabled : %d\n", _clientList.count()+1, _maxClient, _currentClient->_id, (_currentClient->_client).status(), (_currentClient->_client).available(), (_currentClient->_client).isKeepAliveEnabled());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +166,7 @@ class TCPServer
|
|||||||
{
|
{
|
||||||
_currentClient->closeConnection();
|
_currentClient->closeConnection();
|
||||||
#ifdef DEBUG_TCPS
|
#ifdef DEBUG_TCPS
|
||||||
Serial.print("TCPServer : Client was discarded : ");Serial.println(_currentClient->_id);
|
Serial.printf("TCPServer : Client was discarded : %u\n", _currentClient->_id);
|
||||||
#endif
|
#endif
|
||||||
delete _currentClient;
|
delete _currentClient;
|
||||||
_currentClient = NULL;
|
_currentClient = NULL;
|
||||||
@ -167,9 +182,8 @@ class TCPServer
|
|||||||
{
|
{
|
||||||
if(client->_dataSize > 0 && ((char) client->_data[0] != '\r' && (char) client->_data[0] != '\n'))
|
if(client->_dataSize > 0 && ((char) client->_data[0] != '\r' && (char) client->_data[0] != '\n'))
|
||||||
{
|
{
|
||||||
Serial.printf("Client --> %u : #%s#\r\n", client->_id, (char *)client->_data);
|
Serial.printf("Client --> %u : #%s#\r\n", client->_id, (char *)client->_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
client->freeDataBuffer(client->_dataSize);
|
client->freeDataBuffer(client->_dataSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,15 +197,15 @@ class TCPServer
|
|||||||
if(_clientList.getRef(i)->_id == freeId)
|
if(_clientList.getRef(i)->_id == freeId)
|
||||||
{
|
{
|
||||||
freeId++;
|
freeId++;
|
||||||
i = -1;
|
i = -1; //We start from 0 again
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return freeId;
|
return freeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean _serverStarted;
|
boolean _serverStarted;
|
||||||
uint8_t _maxClient;
|
uint8_t _maxClient, _TKACount = 0;
|
||||||
uint16_t _clientDataBufferSize;
|
uint16_t _clientDataBufferSize, _TKAIdleSec = 0, _TKAIntvSec = 0;
|
||||||
WiFiServer _wifiServer;
|
WiFiServer _wifiServer;
|
||||||
T *_currentClient; //current client to be processed
|
T *_currentClient; //current client to be processed
|
||||||
List<T> _clientList;
|
List<T> _clientList;
|
||||||
|
Loading…
Reference in New Issue
Block a user