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@0:1405a58a7e8d, 2016-04-03 (annotated)
- Committer:
- 13075593
- Date:
- Sun Apr 03 15:44:20 2016 +0000
- Revision:
- 0:1405a58a7e8d
- Child:
- 1:5b6c5c2a33d0
Read Config File;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| 13075593 | 0:1405a58a7e8d | 1 | #include "ConfigurationFile.h" |
| 13075593 | 0:1405a58a7e8d | 2 | |
| 13075593 | 0:1405a58a7e8d | 3 | ConfigurationFile::ConfigurationFile() |
| 13075593 | 0:1405a58a7e8d | 4 | { |
| 13075593 | 0:1405a58a7e8d | 5 | PC_Comm _pc; |
| 13075593 | 0:1405a58a7e8d | 6 | pc = _pc.pc; |
| 13075593 | 0:1405a58a7e8d | 7 | } |
| 13075593 | 0:1405a58a7e8d | 8 | |
| 13075593 | 0:1405a58a7e8d | 9 | ConfigurationFile::~ConfigurationFile() |
| 13075593 | 0:1405a58a7e8d | 10 | { |
| 13075593 | 0:1405a58a7e8d | 11 | |
| 13075593 | 0:1405a58a7e8d | 12 | } |
| 13075593 | 0:1405a58a7e8d | 13 | |
| 13075593 | 0:1405a58a7e8d | 14 | void ConfigurationFile::setIP() |
| 13075593 | 0:1405a58a7e8d | 15 | { |
| 13075593 | 0:1405a58a7e8d | 16 | char value[BUFSIZ]; |
| 13075593 | 0:1405a58a7e8d | 17 | if (cfg.getValue( "IP", &value[0], sizeof(value))) |
| 13075593 | 0:1405a58a7e8d | 18 | { |
| 13075593 | 0:1405a58a7e8d | 19 | printf("'%s'='%s'\n", "IP", value); |
| 13075593 | 0:1405a58a7e8d | 20 | string s = value; |
| 13075593 | 0:1405a58a7e8d | 21 | ip = s; |
| 13075593 | 0:1405a58a7e8d | 22 | } |
| 13075593 | 0:1405a58a7e8d | 23 | else |
| 13075593 | 0:1405a58a7e8d | 24 | { |
| 13075593 | 0:1405a58a7e8d | 25 | error("Failure to read IP key"); |
| 13075593 | 0:1405a58a7e8d | 26 | } |
| 13075593 | 0:1405a58a7e8d | 27 | } |
| 13075593 | 0:1405a58a7e8d | 28 | |
| 13075593 | 0:1405a58a7e8d | 29 | string ConfigurationFile::getIP() |
| 13075593 | 0:1405a58a7e8d | 30 | { |
| 13075593 | 0:1405a58a7e8d | 31 | return ip; |
| 13075593 | 0:1405a58a7e8d | 32 | } |
| 13075593 | 0:1405a58a7e8d | 33 | |
| 13075593 | 0:1405a58a7e8d | 34 | void ConfigurationFile::setMask() |
| 13075593 | 0:1405a58a7e8d | 35 | { |
| 13075593 | 0:1405a58a7e8d | 36 | char value[BUFSIZ]; |
| 13075593 | 0:1405a58a7e8d | 37 | if (cfg.getValue( "MASK", &value[0], sizeof(value))) |
| 13075593 | 0:1405a58a7e8d | 38 | { |
| 13075593 | 0:1405a58a7e8d | 39 | printf("'%s'='%s'\n", "MASK", value); |
| 13075593 | 0:1405a58a7e8d | 40 | string s = value; |
| 13075593 | 0:1405a58a7e8d | 41 | mask = s; |
| 13075593 | 0:1405a58a7e8d | 42 | } |
| 13075593 | 0:1405a58a7e8d | 43 | else |
| 13075593 | 0:1405a58a7e8d | 44 | { |
| 13075593 | 0:1405a58a7e8d | 45 | error("Failure to read MASK key"); |
| 13075593 | 0:1405a58a7e8d | 46 | } |
| 13075593 | 0:1405a58a7e8d | 47 | } |
| 13075593 | 0:1405a58a7e8d | 48 | |
| 13075593 | 0:1405a58a7e8d | 49 | string ConfigurationFile::getMask() |
| 13075593 | 0:1405a58a7e8d | 50 | { |
| 13075593 | 0:1405a58a7e8d | 51 | return mask; |
| 13075593 | 0:1405a58a7e8d | 52 | } |
| 13075593 | 0:1405a58a7e8d | 53 | |
| 13075593 | 0:1405a58a7e8d | 54 | void ConfigurationFile::setGateway() |
| 13075593 | 0:1405a58a7e8d | 55 | { |
| 13075593 | 0:1405a58a7e8d | 56 | char value[BUFSIZ]; |
| 13075593 | 0:1405a58a7e8d | 57 | if (cfg.getValue( "GATEWAY", &value[0], sizeof(value))) |
| 13075593 | 0:1405a58a7e8d | 58 | { |
| 13075593 | 0:1405a58a7e8d | 59 | printf("'%s'='%s'\n", "GATEWAY", value); |
| 13075593 | 0:1405a58a7e8d | 60 | string s = value; |
| 13075593 | 0:1405a58a7e8d | 61 | gateway = s; |
| 13075593 | 0:1405a58a7e8d | 62 | } |
| 13075593 | 0:1405a58a7e8d | 63 | else |
| 13075593 | 0:1405a58a7e8d | 64 | { |
| 13075593 | 0:1405a58a7e8d | 65 | error("Failure to read GATEWAY key"); |
| 13075593 | 0:1405a58a7e8d | 66 | } |
| 13075593 | 0:1405a58a7e8d | 67 | } |
| 13075593 | 0:1405a58a7e8d | 68 | |
| 13075593 | 0:1405a58a7e8d | 69 | string ConfigurationFile::getGateway() |
| 13075593 | 0:1405a58a7e8d | 70 | { |
| 13075593 | 0:1405a58a7e8d | 71 | return gateway; |
| 13075593 | 0:1405a58a7e8d | 72 | } |
| 13075593 | 0:1405a58a7e8d | 73 | |
| 13075593 | 0:1405a58a7e8d | 74 | void ConfigurationFile::setURL() |
| 13075593 | 0:1405a58a7e8d | 75 | { |
| 13075593 | 0:1405a58a7e8d | 76 | char value[BUFSIZ]; |
| 13075593 | 0:1405a58a7e8d | 77 | if (cfg.getValue( "URL", &value[0], sizeof(value))) |
| 13075593 | 0:1405a58a7e8d | 78 | { |
| 13075593 | 0:1405a58a7e8d | 79 | printf("'%s'='%s'\n", "URL", value); |
| 13075593 | 0:1405a58a7e8d | 80 | string s = value; |
| 13075593 | 0:1405a58a7e8d | 81 | url = s; |
| 13075593 | 0:1405a58a7e8d | 82 | } |
| 13075593 | 0:1405a58a7e8d | 83 | else |
| 13075593 | 0:1405a58a7e8d | 84 | { |
| 13075593 | 0:1405a58a7e8d | 85 | error("Failure to read URL key"); |
| 13075593 | 0:1405a58a7e8d | 86 | } |
| 13075593 | 0:1405a58a7e8d | 87 | } |
| 13075593 | 0:1405a58a7e8d | 88 | |
| 13075593 | 0:1405a58a7e8d | 89 | string ConfigurationFile::getURL() |
| 13075593 | 0:1405a58a7e8d | 90 | { |
| 13075593 | 0:1405a58a7e8d | 91 | return url; |
| 13075593 | 0:1405a58a7e8d | 92 | } |
| 13075593 | 0:1405a58a7e8d | 93 | |
| 13075593 | 0:1405a58a7e8d | 94 | |
| 13075593 | 0:1405a58a7e8d | 95 | void ConfigurationFile::readServerEthernetConfiguration() |
| 13075593 | 0:1405a58a7e8d | 96 | { |
| 13075593 | 0:1405a58a7e8d | 97 | setIP(); |
| 13075593 | 0:1405a58a7e8d | 98 | setMask(); |
| 13075593 | 0:1405a58a7e8d | 99 | setGateway(); |
| 13075593 | 0:1405a58a7e8d | 100 | setURL(); |
| 13075593 | 0:1405a58a7e8d | 101 | } |
| 13075593 | 0:1405a58a7e8d | 102 | |
| 13075593 | 0:1405a58a7e8d | 103 | void ConfigurationFile::readNodeEthernetConfiguration() |
| 13075593 | 0:1405a58a7e8d | 104 | { |
| 13075593 | 0:1405a58a7e8d | 105 | setIP(); |
| 13075593 | 0:1405a58a7e8d | 106 | setMask(); |
| 13075593 | 0:1405a58a7e8d | 107 | setGateway(); |
| 13075593 | 0:1405a58a7e8d | 108 | } |
| 13075593 | 0:1405a58a7e8d | 109 | |
| 13075593 | 0:1405a58a7e8d | 110 | void ConfigurationFile::readConfigurationFile(char *pathName) |
| 13075593 | 0:1405a58a7e8d | 111 | { |
| 13075593 | 0:1405a58a7e8d | 112 | if (!cfg.read(pathName)) |
| 13075593 | 0:1405a58a7e8d | 113 | { |
| 13075593 | 0:1405a58a7e8d | 114 | error("Failure to read a configuration file.\n"); |
| 13075593 | 0:1405a58a7e8d | 115 | } |
| 13075593 | 0:1405a58a7e8d | 116 | } |