Compare commits

..

No commits in common. "4c4832e475ac4664627383c49e7974191c1c1acf" and "7fdb7b256e17f253257081e53924dffdd9d4024c" have entirely different histories.

12 changed files with 142 additions and 61 deletions

View File

@ -4,7 +4,7 @@
#include "AbstractParser.h" #include "AbstractParser.h"
#include "CFGDictionary.h" #include "CFGDictionary.h"
#include "SDCardManager.h" #include "SDCardManager.h"
#include "utilities.h" #include "definition.h"
#include "CFGParameterValue.h" #include "CFGParameterValue.h"
//Forward class declaration because of cross includes... //Forward class declaration because of cross includes...

View File

@ -1,9 +1,9 @@
#ifndef FTPSERVER_H #ifndef FTPSERVER_H
#define FTPSERVER_H #define FTPSERVER_H
#include <SD.h>
#include "TCPServer.h" #include "TCPServer.h"
#include "utilities.h" #include "SDCardManager.h"
#include "definition.h"
#include "Dictionary.h" #include "Dictionary.h"
//#define DEBUG_FTPS //#define DEBUG_FTPS
#define READ_BUFFER_SIZE 2048 //2048 is max to read sd card, more will crash #define READ_BUFFER_SIZE 2048 //2048 is max to read sd card, more will crash
@ -18,12 +18,12 @@ class FTPServer : public TCPServer<T>
enum BinaryFlag {OFF = 0, ON}; enum BinaryFlag {OFF = 0, ON};
enum FtpMsgCode {_150, _200, _215, _220, _221, _230, _226, _227, _250, _257, _331, _350, _451, _5_502, _504, _530, _550 }; enum FtpMsgCode {_150, _200, _215, _220, _221, _230, _226, _227, _250, _257, _331, _350, _451, _5_502, _504, _530, _550 };
FTPServer(uint16_t port = 21, SDClass *sdClass = NULL, const char *login = NULL, const char *password = NULL, uint8_t maxClient = MAX_CLIENT, uint16_t clientCommandDataBufferSize = 255) : TCPServer<T>(port, maxClient, clientCommandDataBufferSize), FTPServer(uint16_t port = 21, SDCardManager *sdCardManager = NULL, const char *login = NULL, const char *password = NULL, uint8_t maxClient = MAX_CLIENT, uint16_t clientCommandDataBufferSize = 255) : TCPServer<T>(port, maxClient, clientCommandDataBufferSize),
_login(NULL), _login(NULL),
_password(NULL), _password(NULL),
_dataPort(1024), _dataPort(1024),
_dataServer(_dataPort), _dataServer(_dataPort),
_sdClass(sdClass) _sdCardManager(sdCardManager)
{ {
if (login != NULL) if (login != NULL)
{ {
@ -65,11 +65,6 @@ class FTPServer : public TCPServer<T>
} }
} }
virtual void setFTPDir(const char *FTPDir)
{
_FTPDir = FTPDir;
}
protected: protected:
virtual T* createNewClient(WiFiClient wc) virtual T* createNewClient(WiFiClient wc)
{ {
@ -196,10 +191,10 @@ class FTPServer : public TCPServer<T>
{ {
if(client->_fileRecvBytes == 0) //File was just created empty if(client->_fileRecvBytes == 0) //File was just created empty
{ {
if(_sdClass->exists(client->_currentFile)) if(_sdCardManager->exists(client->_currentFile))
_sdClass->remove(client->_currentFile); _sdCardManager->remove(client->_currentFile);
File file2create = _sdClass->open(client->_currentFile, FILE_WRITE); File file2create = _sdCardManager->open(client->_currentFile, FILE_WRITE);
file2create.close(); file2create.close();
#ifdef DEBUG_FTPS #ifdef DEBUG_FTPS
@ -280,7 +275,7 @@ class FTPServer : public TCPServer<T>
processCommands(client); processCommands(client);
break; break;
case INIT: case INIT:
_FTPDir ? client->setCurrentDirectory(_FTPDir) : client->setCurrentDirectory(""); client->setCurrentDirectory(FTP_DIR);
client->_ftpClientState = WAITING_FOR_COMMANDS; client->_ftpClientState = WAITING_FOR_COMMANDS;
break; break;
} }
@ -560,7 +555,7 @@ class FTPServer : public TCPServer<T>
Serial.printf("Final dirName : #%s#\n",dirNameWithPath); Serial.printf("Final dirName : #%s#\n",dirNameWithPath);
#endif #endif
if(_sdClass->mkdir(dirNameWithPath)) if(_sdCardManager->mkdir(dirNameWithPath))
{ {
client->_client.printf("257 \"%s\"\r\n", dirNameWithPath); client->_client.printf("257 \"%s\"\r\n", dirNameWithPath);
} }
@ -596,7 +591,7 @@ class FTPServer : public TCPServer<T>
Serial.printf("pathDirName to delete : #%s#\n",dirNameWithPath); Serial.printf("pathDirName to delete : #%s#\n",dirNameWithPath);
#endif #endif
if(_sdClass->rmdir(dirNameWithPath)) if(_sdCardManager->rmdir(dirNameWithPath))
{ {
client->_client.println("250 Requested file action okay."); client->_client.println("250 Requested file action okay.");
} }
@ -682,7 +677,7 @@ class FTPServer : public TCPServer<T>
Serial.printf("file to delete : #%s#\n",file2deleteNameWithPath); Serial.printf("file to delete : #%s#\n",file2deleteNameWithPath);
#endif #endif
if(_sdClass->remove(file2deleteNameWithPath)) if(_sdCardManager->remove(file2deleteNameWithPath))
{ {
client->_client.println("250 Requested file action okay."); client->_client.println("250 Requested file action okay.");
} }
@ -752,7 +747,7 @@ class FTPServer : public TCPServer<T>
Serial.printf("Old name : %s --> %s\n",client->_currentFile,file2RenameNameWithPath); Serial.printf("Old name : %s --> %s\n",client->_currentFile,file2RenameNameWithPath);
#endif #endif
if(_sdClass->rename(client->_currentFile,file2RenameNameWithPath)) if(_sdCardManager->rename(client->_currentFile,file2RenameNameWithPath))
{ {
client->_client.println("250 Requested file action okay."); client->_client.println("250 Requested file action okay.");
}else }else
@ -794,10 +789,10 @@ class FTPServer : public TCPServer<T>
{ {
if (client->_currentFile != NULL) if (client->_currentFile != NULL)
{ {
if(_sdClass->exists(client->_currentFile) && client->_fileRecvBytes == 0 && !append) if(_sdCardManager->exists(client->_currentFile) && client->_fileRecvBytes == 0 && !append)
_sdClass->remove(client->_currentFile); _sdCardManager->remove(client->_currentFile);
File fileBeeingReceived = _sdClass->open(client->_currentFile, FILE_WRITE); File fileBeeingReceived = _sdCardManager->open(client->_currentFile, FILE_WRITE);
if(fileBeeingReceived) if(fileBeeingReceived)
{ {
@ -835,7 +830,7 @@ class FTPServer : public TCPServer<T>
#ifdef DEBUG_FTPS #ifdef DEBUG_FTPS
Serial.printf("Directory : %s\n",client->_currentDirectory); Serial.printf("Directory : %s\n",client->_currentDirectory);
#endif #endif
File currentDirectory = _sdClass->open(client->_currentDirectory); File currentDirectory = _sdCardManager->open(client->_currentDirectory);
if (currentDirectory) if (currentDirectory)
{ {
currentDirectory.rewindDirectory(); currentDirectory.rewindDirectory();
@ -891,7 +886,7 @@ class FTPServer : public TCPServer<T>
if (client->_currentFile != NULL) if (client->_currentFile != NULL)
{ {
uint8_t sendBuffer[READ_BUFFER_SIZE]; uint8_t sendBuffer[READ_BUFFER_SIZE];
File fileToSend = _sdClass->open(client->_currentFile); File fileToSend = _sdCardManager->open(client->_currentFile);
if (fileToSend) if (fileToSend)
{ {
@ -997,11 +992,10 @@ class FTPServer : public TCPServer<T>
char *_login; char *_login;
char *_password; char *_password;
const char *_FTPDir = NULL; //Pointer to constant string and char * cont is a constant pointer to string
uint16_t _dataPort; uint16_t _dataPort;
WiFiServer _dataServer; //In passive mode, the FTP server opens two different ports (one for the commands and the other for the data stream) WiFiServer _dataServer; //In passive mode, the FTP server opens two different ports (one for the commands and the other for the data stream)
SDClass *_sdClass; SDCardManager *_sdCardManager;
}; };
#endif //FTPSERVER_H #endif //FTPSERVER_H

View File

@ -1,8 +1,7 @@
#ifndef IOMANAGER_H #ifndef IOMANAGER_H
#define IOMANAGER_H #define IOMANAGER_H
#include <PCF8574.h>
#include "definition.h" #include "definition.h"
#include <PCF8574.h>
class IOManager class IOManager
{ {

View File

@ -13,7 +13,7 @@ _rtcManager(_rtc),
_connectivityManager(NULL), _connectivityManager(NULL),
//_webServerManager(80, &_sdCardManager), //_webServerManager(80, &_sdCardManager),
_webServer(80, &_sdCardManager, 10), _webServer(80, &_sdCardManager, 10),
_ftpServer(21, &_sdCardManager, "ESP8266", "12345678", 10), _ftpServer(21, &_sdCardManager, "ESP8266", "12345678"),
_dbWSServer(81), _dbWSServer(81),
_pcf(_boardConfig.getI2C_IOExpanderAddress(), Wire), _pcf(_boardConfig.getI2C_IOExpanderAddress(), Wire),
_ioManager(_pcf), _ioManager(_pcf),
@ -32,7 +32,7 @@ _rtcManager(_rtc),
_connectivityManager(NULL), _connectivityManager(NULL),
//_webServerManager(webServerPort, &_sdCardManager), //_webServerManager(webServerPort, &_sdCardManager),
_webServer(webServerPort, &_sdCardManager, 10), _webServer(webServerPort, &_sdCardManager, 10),
_ftpServer(ftpServerPort, &_sdCardManager, "ESP8266", "12345678", 10), _ftpServer(ftpServerPort, &_sdCardManager, "ESP8266", "12345678"),
_dbWSServer(81), _dbWSServer(81),
_pcf(_boardConfig.getI2C_IOExpanderAddress(), Wire), _pcf(_boardConfig.getI2C_IOExpanderAddress(), Wire),
_ioManager(_pcf), _ioManager(_pcf),
@ -70,9 +70,6 @@ void SAB::initCommonConfig()
_powerUpTime = _rtcManager.getDateTime(); _powerUpTime = _rtcManager.getDateTime();
//We set the different servers : //We set the different servers :
_webServer.setWWWDir(WWW_DIR);
_ftpServer.setFTPDir(FTP_DIR);
//We start the servers
_dbWSServer.begin(); _dbWSServer.begin();
_webServer.enableTCPKeepAlive(15,5,5); _webServer.enableTCPKeepAlive(15,5,5);
_ftpServer.enableTCPKeepAlive(15,5,5); _ftpServer.enableTCPKeepAlive(15,5,5);

View File

@ -196,7 +196,7 @@ void ScreenManager::iterateThroughList()
} }
} }
ScreenManager::ViewLink* ScreenManager::getLinkByUID(ViewLinkedList viewLinkedList, const unsigned char UID) ViewLink* ScreenManager::getLinkByUID(ViewLinkedList viewLinkedList, const unsigned char UID)
{ {
if(isListEmpty(viewLinkedList)) if(isListEmpty(viewLinkedList))
return NULL; return NULL;

View File

@ -2,6 +2,7 @@
#define SCREENMANAGER_H #define SCREENMANAGER_H
#include <Adafruit_SSD1306.h> #include <Adafruit_SSD1306.h>
#include "definition.h"
#include "SDCardManager.h" #include "SDCardManager.h"
#include "CFGFileParser.h" #include "CFGFileParser.h"
#include "CFGDictionary.h" #include "CFGDictionary.h"
@ -12,14 +13,6 @@ class ScreenManager
friend class SAB; friend class SAB;
public: public:
enum Error {OK, MALLOC_FAILED, VIEW_NOT_FOUND, VIEW_FUNC_UNDEFINED, VIEW_FAILED_TO_EXECUTE, CURRENT_VIEW_UNDEFINED}; enum Error {OK, MALLOC_FAILED, VIEW_NOT_FOUND, VIEW_FUNC_UNDEFINED, VIEW_FAILED_TO_EXECUTE, CURRENT_VIEW_UNDEFINED};
//Data structure for the view handling
typedef struct viewLink
{
boolean (*viewLogicFunction)(Adafruit_SSD1306&, void*);
void *pData;
const int UID;
struct viewLink *next, *previous;
} ViewLink, *ViewLinkedList;
boolean addView(boolean (*viewLogicFunction)(Adafruit_SSD1306&, void*), void *pData, const unsigned char UID); boolean addView(boolean (*viewLogicFunction)(Adafruit_SSD1306&, void*), void *pData, const unsigned char UID);
boolean removeView(const unsigned char UID); boolean removeView(const unsigned char UID);

View File

@ -1,5 +1,5 @@
#include "Dictionary.h" #include "Dictionary.h"
#include "utilities.h" #include "definition.h"
Dictionary<DictionaryHelper::StringEntity> *DictionaryHelper::StringEntity::split(char character) Dictionary<DictionaryHelper::StringEntity> *DictionaryHelper::StringEntity::split(char character)
{ {

View File

@ -1,11 +1,10 @@
#ifndef WEBSERVER_H #ifndef WEBSERVER_H
#define WEBSERVER_H #define WEBSERVER_H
#include <SD.h>
#include "TCPServer.h" #include "TCPServer.h"
#include "Dictionary.h" #include "Dictionary.h"
#include "SDCardManager.h"
#include "HttpConstants.h" #include "HttpConstants.h"
#include "utilities.h"
//#define DEBUG_WEBS //#define DEBUG_WEBS
#define READ_WRITE_BUFFER_SIZE 2000 #define READ_WRITE_BUFFER_SIZE 2000
@ -33,7 +32,7 @@ class WEBServer : public TCPServer<T>, public HttpConstants
uint16_t maxBodyBuffer; uint16_t maxBodyBuffer;
}; };
WEBServer(uint16_t port = 80, SDClass *sdClass = NULL, uint8_t maxClient = MAX_CLIENT, uint16_t clientDataBufferSize = 255) : TCPServer<T>(port, maxClient, clientDataBufferSize), _sdClass(sdClass) {} WEBServer(uint16_t port = 80, SDCardManager *sdCardManager = NULL, uint8_t maxClient = MAX_CLIENT, uint16_t clientDataBufferSize = 255) : TCPServer<T>(port, maxClient, clientDataBufferSize), _sdCardManager(sdCardManager) {}
boolean addApiRoutine(const char *uri, boolean (*apiRoutine)(HttpRequestData&, WiFiClient*, void*), void *pData, HttpRequestMethod HRM = UNDEFINED) boolean addApiRoutine(const char *uri, boolean (*apiRoutine)(HttpRequestData&, WiFiClient*, void*), void *pData, HttpRequestMethod HRM = UNDEFINED)
{ {
@ -58,11 +57,6 @@ class WEBServer : public TCPServer<T>, public HttpConstants
free(buffer); free(buffer);
} }
} }
void setWWWDir(const char *WWWDir)
{
_WWWDir = WWWDir;
}
protected: protected:
private: private:
virtual T* createNewClient(WiFiClient wc) virtual T* createNewClient(WiFiClient wc)
@ -476,7 +470,7 @@ class WEBServer : public TCPServer<T>, public HttpConstants
boolean sendPageToClientFromSdCard(T *client) boolean sendPageToClientFromSdCard(T *client)
{ {
if(_sdClass != NULL) if(_sdCardManager != NULL)
{ {
File pageToSend; File pageToSend;
char *filePath(NULL), *header(NULL); char *filePath(NULL), *header(NULL);
@ -486,7 +480,7 @@ class WEBServer : public TCPServer<T>, public HttpConstants
switch(client->_httpRequestData.HRM) switch(client->_httpRequestData.HRM)
{ {
case GET: case GET:
filePath = getFilePathByHttpResource(_WWWDir, client->_httpRequestData.httpResource); filePath = getFilePathByHttpResource(client->_httpRequestData.httpResource);
if(filePath == NULL) if(filePath == NULL)
{ {
sendInfoResponse(HTTP_CODE::HTTP_CODE_INTERNAL_SERVER_ERROR, client, "Failed to allocate memory for the filePath"); sendInfoResponse(HTTP_CODE::HTTP_CODE_INTERNAL_SERVER_ERROR, client, "Failed to allocate memory for the filePath");
@ -498,7 +492,7 @@ class WEBServer : public TCPServer<T>, public HttpConstants
Serial.println(filePath); Serial.println(filePath);
#endif #endif
pageToSend = _sdClass->open(filePath); pageToSend = _sdCardManager->open(filePath);
free(filePath);filePath = NULL; free(filePath);filePath = NULL;
//If we couldn't open the file //If we couldn't open the file
@ -716,16 +710,16 @@ class WEBServer : public TCPServer<T>, public HttpConstants
return p != NULL ? p+1 : NULL; return p != NULL ? p+1 : NULL;
} }
static char *getFilePathByHttpResource(const char *WWWDir, char *res) static char *getFilePathByHttpResource(char *res)
{ {
uint16_t buffSize = (WWWDir ? strlen(WWWDir) : 0 /*default is / */) + (strcmp(res, "/") == 0 ? 10:strlen(res)) + 1;//10 for /index.htm +1 for \0 uint16_t buffSize = strlen(WWW_DIR) + (strcmp(res, "/") == 0 ? 10:strlen(res)) + 1;//10 for /index.htm +1 for \0
char *filePath = (char*) malloc( sizeof(char) * buffSize); char *filePath = (char*) malloc( sizeof(char) * buffSize);
if(filePath == NULL) if(filePath == NULL)
return NULL; return NULL;
WWWDir ? strcpy(filePath, WWWDir) : strcpy(filePath, ""); strcpy(filePath, WWW_DIR);
strcat(filePath, (strcmp(res, "/") == 0) ? "/index.htm":res); strcat(filePath, strcmp(res, "/") == 0 ? "/index.htm":res);
#ifdef DEBUG_FILEPATH #ifdef DEBUG_FILEPATH
Serial.println(res); Serial.println(res);
@ -756,8 +750,7 @@ class WEBServer : public TCPServer<T>, public HttpConstants
}; };
Dictionary<ApiRoutine> _apiDictionary; Dictionary<ApiRoutine> _apiDictionary;
SDClass *_sdClass; SDCardManager *_sdCardManager;
const char *_WWWDir = NULL; //Website root folder
}; };
#endif //WEBSERVER_H #endif //WEBSERVER_H

View File

@ -87,7 +87,7 @@ void setup()
sab.getTaskSchedulerManager().addTask(1, TaskSchedulerManagerHelper::Schedule::scheduleBuilder()->setSeconds(10), &(task_batt_sensing), &v1p); sab.getTaskSchedulerManager().addTask(1, TaskSchedulerManagerHelper::Schedule::scheduleBuilder()->setSeconds(10), &(task_batt_sensing), &v1p);
//dataLogger.client.keepAlive(true); //dataLogger.client.keepAlive(true);
//sab.getTaskSchedulerManager().addTask(2, TaskSchedulerManagerHelper::Schedule::scheduleBuilder()->setSeconds(1)->setTriggerRightAway(false), &(task_post_data_logger), &dataLogger); //sab.getTaskSchedulerManager().addTask(2, TaskSchedulerManagerHelper::Schedule::scheduleBuilder()->setSeconds(1)->setTriggerRightAway(false), &(task_post_data_logger), &dataLogger);
Serial.println("End setup"); Serial.println("End setup");
} }

88
src/app/definition.cpp Normal file
View File

@ -0,0 +1,88 @@
#include "definition.h"
char *addChar(char *pointer, const char character)
{
char *tempAddr = NULL;
if(pointer == NULL)
{
tempAddr = (char *) realloc(pointer, 2*sizeof(char));
if(tempAddr == NULL)
return NULL;
else
{
pointer = tempAddr;
pointer[0] = character;
pointer[1] = '\0';
}
}
else
{
tempAddr = (char *) realloc(pointer, (strlen(pointer)+2)*sizeof(char));
if(tempAddr == NULL)
{
free(pointer);
return NULL;
}
else
{
pointer = tempAddr;
pointer[strlen(pointer)+1] = '\0';
pointer[strlen(pointer)] = character;
}
}
return pointer;
}
char *dateTimeFormater(char *pointer, const uint8_t value, const char character)
{
if(pointer == NULL)
return pointer;
if(value < 10)
{
sprintf(pointer,"%d", value);
*(pointer+1) = *(pointer);*(pointer) = character;*(pointer+2) = '\0';
}
else
sprintf(pointer,"%d", value);
return pointer;
}
char *lastIndexOf(char *str, const char character)
{
char *last(NULL), *current(str);
do
{
current = strchr(current, character);
if(current != NULL)
{
last = current;
if(*(current+1) == '\0')break;
current += 1;
}
}while(current != NULL);
return last;
}
/**
* The monthNumTo3LetterAbbreviation function takes the month number from 1 to 12 and returns the abbreviation in a 3 letter
* format.
*/
uint32_t monthNumTo3LetterAbbreviation(const uint8_t monthNumber)
{
/**
* This array contains months as 3 letter abbreviations
* Jan is written \0naJ and in hex : 0x006E614A an so on. They are thus 4Bytes aligned and easy to put and read back from prog mem :)
*/
static const uint32_t PROGMEM monthArray[] = {0x6E614A, 0x626546, 0x72614D, 0x727041, 0x79614D, 0x6E754A, 0x6C754A, 0x677541, 0x706553, 0x74634F, 0x766f4E, 0x636544};
uint32_t toReturn(0x6E614A); //Default to Jan.
if(monthNumber >= 1 && monthNumber <= 12)
toReturn = monthArray[monthNumber - 1];
return toReturn;
}

View File

@ -42,4 +42,21 @@ typedef enum { GPIO_0 = 0,
typedef enum { OR_0 = 2, OR_90 = 3, OR_180 = 0, OR_270 = 1 } Orientation; typedef enum { OR_0 = 2, OR_90 = 3, OR_180 = 0, OR_270 = 1 } Orientation;
typedef enum { BIT = 0, BYTE, KBIT, KBYTE, MBIT, MBYTE, GBIT, GBYTE } SizeUnit; typedef enum { BIT = 0, BYTE, KBIT, KBYTE, MBIT, MBYTE, GBIT, GBYTE } SizeUnit;
//Data structure for the view handling
typedef struct viewLink{
boolean (*viewLogicFunction)(Adafruit_SSD1306&, void*);
void *pData;
const int UID;
struct viewLink *next, *previous;
} ViewLink, *ViewLinkedList;
char *addChar(char *pointer, const char character);
char *lastIndexOf(char *str, const char character);
char *dateTimeFormater(char *pointer, const uint8_t value, const char character);
uint32_t monthNumTo3LetterAbbreviation(const uint8_t monthNumber);
#endif //DEFINITION_H #endif //DEFINITION_H

View File

@ -11,7 +11,7 @@ boolean task_blink(void *pData)
boolean task_batt_sensing(void *pData) boolean task_batt_sensing(void *pData)
{ {
View1Packet *p = (View1Packet *) pData; View1Packet *p = (View1Packet *) pData;
Serial.printf_P(PSTR("BATT SENSING...\nRunning since : %d s\nWEB Server clients : %u\n"), millis()/1000,p->sab->getWebServer().getConnectedClientsCount()); Serial.printf_P(PSTR("BATT SENSING...\nRunning since : %d s\n"), millis()/1000);
p->powerInfo = p->sab->getPowerManager().getPowerInfo(); p->powerInfo = p->sab->getPowerManager().getPowerInfo();
return true; return true;