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-06
- Revision:
- 4:c8f6d3677937
- Parent:
- 3:7177e463ac52
- Child:
- 6:d5c26e813715
File content as of revision 4:c8f6d3677937:
#include "ConfigurationFile.h"
ConfigurationFile::ConfigurationFile()
{
readConfigurationFile("/local/unit.cfg");
readUnitConfiguration();
}
void ConfigurationFile::readConfigurationFile(char *pathName)
{
LocalFileSystem local("local");
if (!cfg.read(pathName))
{
error("Failure to read a configuration file.\n");
}
}
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::setBroadcastPort()
{
char value[BUFSIZ];
if (cfg.getValue( "BROADCAST", &value[0], sizeof(value)))
{
printf("'%s'='%s'\n", "Broadcast Address", value);
string s = value;
broadcastPort = s;
}
else
{
error("Failure to read Broadcast Address key");
}
}
int ConfigurationFile::getBroadcastPort()
{
return atoi(broadcastPort.c_str());
}
void ConfigurationFile::readUnitConfiguration()
{
setIP();
setMask();
setGateway();
setURL();
setBroadcastPort();
}
void ConfigurationFile::getUnitConfiguration()
{
printf("IP : %s\n",getIP());
printf("Mask : %s\n",getMask());
printf("Gateway : %s\n",getGateway());
printf("URL : %s\n",getURL());
printf("BroadcastPort : %i,\n",getBroadcastPort());
}