Compare commits
No commits in common. "5627ebde48405cd610fdddcfb64924516dbb776c" and "3e193233b4c08b2da6664daa1f37dc2a2fc4d065" have entirely different histories.
5627ebde48
...
3e193233b4
@ -16,7 +16,6 @@ void *CFGFileParser::parseFile()
|
||||
if(!_sdCardManager.isMounted()) return NULL;
|
||||
|
||||
file = _sdCardManager.open(_resource);
|
||||
//We check if the file name is not NULL :-)
|
||||
if(!file)
|
||||
{
|
||||
delete dictioRef;
|
||||
|
@ -46,6 +46,7 @@ CFGParameterValue::~CFGParameterValue()
|
||||
void CFGParameterValue::setValue(const char *value, bool isQuoted)
|
||||
{
|
||||
_quotedValue = isQuoted;
|
||||
|
||||
free(_value);_value = NULL;
|
||||
_value = (char *) malloc((strlen(value) * sizeof(char)) + 1); //+1 for the string terminating character
|
||||
strcpy(_value, value);
|
||||
|
@ -19,30 +19,6 @@ _pcf(_boardConfig.getI2C_IOExpanderAddress(), Wire),
|
||||
_ioManager(_pcf),
|
||||
_taskSchedulerManager(_rtcManager),
|
||||
_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
|
||||
initGPIO();
|
||||
@ -68,11 +44,49 @@ void SAB::initCommonConfig()
|
||||
if(!_pcf.begin()){_error |= IO_INIT_ERR;}
|
||||
|
||||
_powerUpTime = _rtcManager.getDateTime();
|
||||
|
||||
//We set the different servers :
|
||||
_dbWSServer.begin();
|
||||
_webServer.enableTcpKeepAlive(15,5,5);
|
||||
_ftpServer.enableTcpKeepAlive(15,5,5);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
//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();
|
||||
}
|
||||
|
||||
void SAB::initGPIO()
|
||||
|
@ -49,7 +49,6 @@ class SAB
|
||||
private:
|
||||
void initGPIO();
|
||||
static time_t myTimeCallback();
|
||||
void initCommonConfig();
|
||||
const BoardConfig _boardConfig;
|
||||
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include "List.h"
|
||||
#include "TCPClient.h"
|
||||
|
||||
#define MAX_CLIENT 0
|
||||
#define MAX_CLIENT -1
|
||||
//#define DEBUG_TCPS
|
||||
|
||||
|
||||
@ -63,17 +63,6 @@ class TCPServer
|
||||
}
|
||||
}
|
||||
|
||||
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:
|
||||
virtual T* createNewClient(WiFiClient wc)
|
||||
{
|
||||
@ -84,7 +73,7 @@ class TCPServer
|
||||
{
|
||||
WiFiClient wc;
|
||||
|
||||
if(!_maxClient || _maxClient > _clientList.count())
|
||||
if(_maxClient == -1 || _maxClient > _clientList.count())
|
||||
{
|
||||
wc = _wifiServer.available();
|
||||
}
|
||||
@ -92,15 +81,11 @@ class TCPServer
|
||||
if(wc && wc.connected())
|
||||
{
|
||||
T *clientPointer = createNewClient(wc);
|
||||
//We activate the TKA : (The check is internally done in the
|
||||
//ClientContext.h class : ie if one of the provided parameters is 0, then TKA is disabled)
|
||||
(clientPointer->_client).keepAlive(_TKAIdleSec, _TKAIntvSec, _TKACount);
|
||||
|
||||
//Activate keepAlive
|
||||
(clientPointer->_client).keepAlive(15, 5, 5);
|
||||
_clientList.addFirst(clientPointer);
|
||||
#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());
|
||||
if(_TKAIdleSec && _TKAIntvSec && _TKACount)
|
||||
Serial.printf("TCPKeepAlive enabled for client id : %u\n", clientPointer->_id);
|
||||
#endif
|
||||
greetClient(clientPointer);
|
||||
}
|
||||
@ -119,7 +104,7 @@ class TCPServer
|
||||
|
||||
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()
|
||||
@ -148,14 +133,14 @@ class TCPServer
|
||||
else if(!(_currentClient->_client).connected())
|
||||
{
|
||||
#ifdef DEBUG_TCPS
|
||||
Serial.printf("TCPServer : Client disconnected and can be discarded : %u\n", _currentClient->_id);
|
||||
Serial.print("TCPServer : Client disconnected and can be discarded : ");Serial.println(_currentClient->_id);
|
||||
#endif
|
||||
_currentClient->_clientState = TCPClient::DISCARDED;
|
||||
}
|
||||
else //Strange
|
||||
{
|
||||
#ifdef DEBUG_TCPS
|
||||
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());
|
||||
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());
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -166,7 +151,7 @@ class TCPServer
|
||||
{
|
||||
_currentClient->closeConnection();
|
||||
#ifdef DEBUG_TCPS
|
||||
Serial.printf("TCPServer : Client was discarded : %u\n", _currentClient->_id);
|
||||
Serial.print("TCPServer : Client was discarded : ");Serial.println(_currentClient->_id);
|
||||
#endif
|
||||
delete _currentClient;
|
||||
_currentClient = NULL;
|
||||
@ -182,8 +167,9 @@ class TCPServer
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
@ -197,15 +183,15 @@ class TCPServer
|
||||
if(_clientList.getRef(i)->_id == freeId)
|
||||
{
|
||||
freeId++;
|
||||
i = -1; //We start from 0 again
|
||||
i = -1;
|
||||
}
|
||||
}
|
||||
return freeId;
|
||||
}
|
||||
|
||||
boolean _serverStarted;
|
||||
uint8_t _maxClient, _TKACount = 0;
|
||||
uint16_t _clientDataBufferSize, _TKAIdleSec = 0, _TKAIntvSec = 0;
|
||||
uint8_t _maxClient;
|
||||
uint16_t _clientDataBufferSize;
|
||||
WiFiServer _wifiServer;
|
||||
T *_currentClient; //current client to be processed
|
||||
List<T> _clientList;
|
||||
|
Loading…
Reference in New Issue
Block a user