Updated the other classes accordingly to the changes made to the dictionary class

This commit is contained in:
anschrammh 2019-03-28 00:01:48 +01:00
parent 45fc1e468b
commit 1f7f198582
4 changed files with 23 additions and 10 deletions

View File

@ -1,6 +1,6 @@
#include "CFGFileParser.h"
CFGFileParser::CFGFileParser(SDCardManager &sdCardManager, const char *file):AbstractParser(file), _state(INIT), _type(PARAMETER), _sdCardManager(sdCardManager)
CFGFileParser::CFGFileParser(SDCardManager &sdCardManager, const char *file):AbstractParser(file), _state(INIT), _type(PARAMETER), _quotedParameter(false), _quotedValue(false), _sdCardManager(sdCardManager)
{
}
@ -10,7 +10,7 @@ void *CFGFileParser::parseFile()
//Here is the logic for the file parser
File file;
CFGDictionary *dictioRef = new CFGDictionary;
CFGDictionary<CFGParameterValue> *dictioRef = new CFGDictionary<CFGParameterValue>;
char readChar(0), *parsedParameter(NULL), *parsedValue(NULL);
file = _sdCardManager.open(_resource);
@ -23,6 +23,7 @@ void *CFGFileParser::parseFile()
while(file.available())
{
readChar = (char)file.read();
//Do work
switch(_state)
{
@ -77,10 +78,11 @@ void *CFGFileParser::parseFile()
if(parsedParameter != NULL)
{
//printf("%s --> %s\n", parsedParameter, parsedValue);
dictioRef->addParameter(parsedParameter, parsedValue == NULL ? "":parsedValue);
dictioRef->addParameter(parsedParameter, new CFGParameterValue(parsedParameter, parsedValue == NULL ? "":parsedValue, _quotedParameter, _quotedValue));
free(parsedParameter);free(parsedValue);
parsedParameter = NULL;
parsedValue = NULL;
parsedParameter = NULL;parsedValue = NULL;
_quotedParameter = false;_quotedValue = false;
}
}
else if(readChar == ' ') _state = PARAM_SECTION;
@ -104,7 +106,14 @@ void *CFGFileParser::parseFile()
_state = ERROR;
break;
case OPENING_QUOTE:
if(readChar == '\'') _state = PARAM_SECTION;
if(readChar == '\'')
{
_state = PARAM_SECTION;
if(_type == PARAMETER)
_quotedParameter = true;
else
_quotedValue = true;
}
else if((readChar >= 65 && readChar <= 90) || (readChar >= 97 && readChar <= 122) || readChar == ' ' || readChar == '_' || (readChar >= 48 && readChar <= 57))
{
//printf("%c",readChar);

View File

@ -5,6 +5,7 @@
#include "CFGDictionary.h"
#include "SDCardManager.h"
#include "definition.h"
#include "CFGParameterValue.h"
class CFGFileParser : public AbstractParser
{
@ -21,6 +22,8 @@ private:
enum Type {PARAMETER, VALUE};
State _state;
Type _type;
boolean _quotedParameter;
boolean _quotedValue;
SDCardManager &_sdCardManager;
};

View File

@ -15,22 +15,22 @@ ConnectivityManager::ConnectivityManager(SDCardManager *sdCardManager) : _error(
else
{
CFGFileParser cfgFileParser(*sdCardManager, AP_CFG_FILE);
CFGDictionary *cfgDictionary = (CFGDictionary *) cfgFileParser.parseFile();
CFGDictionary<CFGParameterValue> *cfgDictionary = (CFGDictionary<CFGParameterValue> *) cfgFileParser.parseFile();
if(cfgDictionary == NULL)
{
if(!softAP("ESP8266SwissArmyBoard", NULL, 1, false, 8))_error &= AP_SETUP_ERR;
}
else
{
if(!softAP((*cfgDictionary)("SSID").stringValue(), strcmp((*cfgDictionary)("PASSWORD").stringValue(),"") == 0 ? NULL:(*cfgDictionary)("PASSWORD").stringValue(), (*cfgDictionary)("CHANNEL").intValue(), (*cfgDictionary)("SSID_HIDDEN").booleanValue(), (*cfgDictionary)("AP_MAX_CONNECTION").intValue()))_error &= AP_SETUP_ERR;
if(!softAP((*cfgDictionary)("SSID").getValue().stringValue(), strcmp((*cfgDictionary)("PASSWORD").getValue().stringValue(),"") == 0 ? NULL:(*cfgDictionary)("PASSWORD").getValue().stringValue(), (*cfgDictionary)("CHANNEL").getValue().intValue(), (*cfgDictionary)("SSID_HIDDEN").getValue().booleanValue(), (*cfgDictionary)("AP_MAX_CONNECTION").getValue().intValue()))_error &= AP_SETUP_ERR;
delete cfgDictionary;
}
CFGFileParser cfgFileParserSTA(*sdCardManager, STA_CFG_FILE);
cfgDictionary = (CFGDictionary *) cfgFileParserSTA.parseFile();
cfgDictionary = (CFGDictionary<CFGParameterValue> *) cfgFileParserSTA.parseFile();
if(cfgDictionary != NULL)
{
if(!begin((*cfgDictionary)("SSID").stringValue(), (*cfgDictionary)("PASSWORD").stringValue()))_error &= AP_SETUP_ERR;
if(!begin((*cfgDictionary)("SSID").getValue().stringValue(), (*cfgDictionary)("PASSWORD").getValue().stringValue()))_error &= AP_SETUP_ERR;
delete cfgDictionary;
}
}

View File

@ -3,6 +3,7 @@
#include "SAB.h"
#include "views.h"
#include "CFGDictionary.h"
#include "CFGParameterValue.h"
SAB sab;