Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ConfigFile
ConfigurationFile.cpp
- Committer:
- 13075593
- Date:
- 2016-04-04
- Revision:
- 1:5b6c5c2a33d0
- Parent:
- 0:1405a58a7e8d
- Child:
- 2:5af11ca8e085
File content as of revision 1:5b6c5c2a33d0:
#include "ConfigurationFile.h"
ConfigurationFile::ConfigurationFile()
{
}
ConfigurationFile::~ConfigurationFile()
{
}
void ConfigurationFile::setIP()
{
char value[BUFSIZ];
if (cfg.getValue( "IP", &value[0], sizeof(value)))
{
printf("'%s'='%s'\n", "IP", value);
string s = value;
ip = s;
}
else
{
error("Failure to read IP key");
}
}
string ConfigurationFile::getIP()
{
return ip;
}
void ConfigurationFile::setMask()
{
char value[BUFSIZ];
if (cfg.getValue( "MASK", &value[0], sizeof(value)))
{
printf("'%s'='%s'\n", "MASK", value);
string s = value;
mask = s;
}
else
{
error("Failure to read MASK key");
}
}
string ConfigurationFile::getMask()
{
return mask;
}
void ConfigurationFile::setGateway()
{
char value[BUFSIZ];
if (cfg.getValue( "GATEWAY", &value[0], sizeof(value)))
{
printf("'%s'='%s'\n", "GATEWAY", value);
string s = value;
gateway = s;
}
else
{
error("Failure to read GATEWAY key");
}
}
string ConfigurationFile::getGateway()
{
return gateway;
}
void ConfigurationFile::setURL()
{
char value[BUFSIZ];
if (cfg.getValue( "URL", &value[0], sizeof(value)))
{
printf("'%s'='%s'\n", "URL", value);
string s = value;
url = s;
}
else
{
error("Failure to read URL key");
}
}
string ConfigurationFile::getURL()
{
return url;
}
void ConfigurationFile::setServerAddress()
{
char value[BUFSIZ];
if (cfg.getValue( "SERVER", &value[0], sizeof(value)))
{
printf("'%s'='%s'\n", "Server Address", value);
string s = value;
serverAddress = s;
}
else
{
error("Failure to read Server Address key");
}
}
string ConfigurationFile::getServerAddress()
{
return serverAddress;
}
void ConfigurationFile::readServerEthernetConfiguration()
{
setIP();
setMask();
setGateway();
setURL();
}
void ConfigurationFile::readNodeEthernetConfiguration()
{
setIP();
setMask();
setGateway();
setServerAddress();
}
void ConfigurationFile::getServerConfiguration()
{
getIP();
getMask();
getGateway();
getURL();
}
void ConfigurationFile::getNodeConfiguration()
{
getIP();
getMask();
getGateway();
getServerAddress();
}
void ConfigurationFile::readConfigurationFile(char *pathName)
{
if (!cfg.read(pathName))
{
error("Failure to read a configuration file.\n");
}
}