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@2:5af11ca8e085, 2016-04-06 (annotated)
- Committer:
- 13075593
- Date:
- Wed Apr 06 15:46:53 2016 +0000
- Revision:
- 2:5af11ca8e085
- Parent:
- 1:5b6c5c2a33d0
- Child:
- 3:7177e463ac52
Change for broadcast
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 | } |
| 13075593 | 0:1405a58a7e8d | 6 | |
| 13075593 | 0:1405a58a7e8d | 7 | ConfigurationFile::~ConfigurationFile() |
| 13075593 | 0:1405a58a7e8d | 8 | { |
| 13075593 | 0:1405a58a7e8d | 9 | } |
| 13075593 | 0:1405a58a7e8d | 10 | |
| 13075593 | 0:1405a58a7e8d | 11 | void ConfigurationFile::setIP() |
| 13075593 | 0:1405a58a7e8d | 12 | { |
| 13075593 | 0:1405a58a7e8d | 13 | char value[BUFSIZ]; |
| 13075593 | 0:1405a58a7e8d | 14 | if (cfg.getValue( "IP", &value[0], sizeof(value))) |
| 13075593 | 0:1405a58a7e8d | 15 | { |
| 13075593 | 0:1405a58a7e8d | 16 | printf("'%s'='%s'\n", "IP", value); |
| 13075593 | 0:1405a58a7e8d | 17 | string s = value; |
| 13075593 | 0:1405a58a7e8d | 18 | ip = s; |
| 13075593 | 0:1405a58a7e8d | 19 | } |
| 13075593 | 0:1405a58a7e8d | 20 | else |
| 13075593 | 0:1405a58a7e8d | 21 | { |
| 13075593 | 0:1405a58a7e8d | 22 | error("Failure to read IP key"); |
| 13075593 | 0:1405a58a7e8d | 23 | } |
| 13075593 | 0:1405a58a7e8d | 24 | } |
| 13075593 | 0:1405a58a7e8d | 25 | |
| 13075593 | 0:1405a58a7e8d | 26 | string ConfigurationFile::getIP() |
| 13075593 | 0:1405a58a7e8d | 27 | { |
| 13075593 | 0:1405a58a7e8d | 28 | return ip; |
| 13075593 | 0:1405a58a7e8d | 29 | } |
| 13075593 | 0:1405a58a7e8d | 30 | |
| 13075593 | 0:1405a58a7e8d | 31 | void ConfigurationFile::setMask() |
| 13075593 | 0:1405a58a7e8d | 32 | { |
| 13075593 | 0:1405a58a7e8d | 33 | char value[BUFSIZ]; |
| 13075593 | 0:1405a58a7e8d | 34 | if (cfg.getValue( "MASK", &value[0], sizeof(value))) |
| 13075593 | 0:1405a58a7e8d | 35 | { |
| 13075593 | 0:1405a58a7e8d | 36 | printf("'%s'='%s'\n", "MASK", value); |
| 13075593 | 0:1405a58a7e8d | 37 | string s = value; |
| 13075593 | 0:1405a58a7e8d | 38 | mask = s; |
| 13075593 | 0:1405a58a7e8d | 39 | } |
| 13075593 | 0:1405a58a7e8d | 40 | else |
| 13075593 | 0:1405a58a7e8d | 41 | { |
| 13075593 | 0:1405a58a7e8d | 42 | error("Failure to read MASK key"); |
| 13075593 | 0:1405a58a7e8d | 43 | } |
| 13075593 | 0:1405a58a7e8d | 44 | } |
| 13075593 | 0:1405a58a7e8d | 45 | |
| 13075593 | 0:1405a58a7e8d | 46 | string ConfigurationFile::getMask() |
| 13075593 | 0:1405a58a7e8d | 47 | { |
| 13075593 | 0:1405a58a7e8d | 48 | return mask; |
| 13075593 | 0:1405a58a7e8d | 49 | } |
| 13075593 | 0:1405a58a7e8d | 50 | |
| 13075593 | 0:1405a58a7e8d | 51 | void ConfigurationFile::setGateway() |
| 13075593 | 0:1405a58a7e8d | 52 | { |
| 13075593 | 0:1405a58a7e8d | 53 | char value[BUFSIZ]; |
| 13075593 | 0:1405a58a7e8d | 54 | if (cfg.getValue( "GATEWAY", &value[0], sizeof(value))) |
| 13075593 | 0:1405a58a7e8d | 55 | { |
| 13075593 | 0:1405a58a7e8d | 56 | printf("'%s'='%s'\n", "GATEWAY", value); |
| 13075593 | 0:1405a58a7e8d | 57 | string s = value; |
| 13075593 | 0:1405a58a7e8d | 58 | gateway = s; |
| 13075593 | 0:1405a58a7e8d | 59 | } |
| 13075593 | 0:1405a58a7e8d | 60 | else |
| 13075593 | 0:1405a58a7e8d | 61 | { |
| 13075593 | 0:1405a58a7e8d | 62 | error("Failure to read GATEWAY key"); |
| 13075593 | 0:1405a58a7e8d | 63 | } |
| 13075593 | 0:1405a58a7e8d | 64 | } |
| 13075593 | 0:1405a58a7e8d | 65 | |
| 13075593 | 0:1405a58a7e8d | 66 | string ConfigurationFile::getGateway() |
| 13075593 | 0:1405a58a7e8d | 67 | { |
| 13075593 | 0:1405a58a7e8d | 68 | return gateway; |
| 13075593 | 0:1405a58a7e8d | 69 | } |
| 13075593 | 0:1405a58a7e8d | 70 | |
| 13075593 | 0:1405a58a7e8d | 71 | void ConfigurationFile::setURL() |
| 13075593 | 0:1405a58a7e8d | 72 | { |
| 13075593 | 0:1405a58a7e8d | 73 | char value[BUFSIZ]; |
| 13075593 | 0:1405a58a7e8d | 74 | if (cfg.getValue( "URL", &value[0], sizeof(value))) |
| 13075593 | 0:1405a58a7e8d | 75 | { |
| 13075593 | 0:1405a58a7e8d | 76 | printf("'%s'='%s'\n", "URL", value); |
| 13075593 | 0:1405a58a7e8d | 77 | string s = value; |
| 13075593 | 0:1405a58a7e8d | 78 | url = s; |
| 13075593 | 0:1405a58a7e8d | 79 | } |
| 13075593 | 0:1405a58a7e8d | 80 | else |
| 13075593 | 0:1405a58a7e8d | 81 | { |
| 13075593 | 0:1405a58a7e8d | 82 | error("Failure to read URL key"); |
| 13075593 | 0:1405a58a7e8d | 83 | } |
| 13075593 | 0:1405a58a7e8d | 84 | } |
| 13075593 | 0:1405a58a7e8d | 85 | |
| 13075593 | 0:1405a58a7e8d | 86 | string ConfigurationFile::getURL() |
| 13075593 | 0:1405a58a7e8d | 87 | { |
| 13075593 | 0:1405a58a7e8d | 88 | return url; |
| 13075593 | 0:1405a58a7e8d | 89 | } |
| 13075593 | 0:1405a58a7e8d | 90 | |
| 13075593 | 2:5af11ca8e085 | 91 | void ConfigurationFile::setBroadcastAddress() |
| 13075593 | 1:5b6c5c2a33d0 | 92 | { |
| 13075593 | 1:5b6c5c2a33d0 | 93 | char value[BUFSIZ]; |
| 13075593 | 2:5af11ca8e085 | 94 | if (cfg.getValue( "BROADCAST", &value[0], sizeof(value))) |
| 13075593 | 1:5b6c5c2a33d0 | 95 | { |
| 13075593 | 2:5af11ca8e085 | 96 | printf("'%s'='%s'\n", "Broadcast Address", value); |
| 13075593 | 1:5b6c5c2a33d0 | 97 | string s = value; |
| 13075593 | 2:5af11ca8e085 | 98 | broadcastAddress = s; |
| 13075593 | 1:5b6c5c2a33d0 | 99 | } |
| 13075593 | 1:5b6c5c2a33d0 | 100 | else |
| 13075593 | 1:5b6c5c2a33d0 | 101 | { |
| 13075593 | 2:5af11ca8e085 | 102 | error("Failure to read Broadcast Address key"); |
| 13075593 | 1:5b6c5c2a33d0 | 103 | } |
| 13075593 | 1:5b6c5c2a33d0 | 104 | } |
| 13075593 | 1:5b6c5c2a33d0 | 105 | |
| 13075593 | 2:5af11ca8e085 | 106 | string ConfigurationFile::getBroadcastAddress() |
| 13075593 | 1:5b6c5c2a33d0 | 107 | { |
| 13075593 | 2:5af11ca8e085 | 108 | return broadcastAddress; |
| 13075593 | 1:5b6c5c2a33d0 | 109 | } |
| 13075593 | 1:5b6c5c2a33d0 | 110 | |
| 13075593 | 0:1405a58a7e8d | 111 | |
| 13075593 | 0:1405a58a7e8d | 112 | void ConfigurationFile::readServerEthernetConfiguration() |
| 13075593 | 0:1405a58a7e8d | 113 | { |
| 13075593 | 0:1405a58a7e8d | 114 | setIP(); |
| 13075593 | 0:1405a58a7e8d | 115 | setMask(); |
| 13075593 | 0:1405a58a7e8d | 116 | setGateway(); |
| 13075593 | 0:1405a58a7e8d | 117 | setURL(); |
| 13075593 | 2:5af11ca8e085 | 118 | setBroadcastAddress(); |
| 13075593 | 0:1405a58a7e8d | 119 | } |
| 13075593 | 0:1405a58a7e8d | 120 | |
| 13075593 | 0:1405a58a7e8d | 121 | void ConfigurationFile::readNodeEthernetConfiguration() |
| 13075593 | 0:1405a58a7e8d | 122 | { |
| 13075593 | 0:1405a58a7e8d | 123 | setIP(); |
| 13075593 | 0:1405a58a7e8d | 124 | setMask(); |
| 13075593 | 0:1405a58a7e8d | 125 | setGateway(); |
| 13075593 | 2:5af11ca8e085 | 126 | setBroadcastAddress(); |
| 13075593 | 1:5b6c5c2a33d0 | 127 | } |
| 13075593 | 1:5b6c5c2a33d0 | 128 | |
| 13075593 | 1:5b6c5c2a33d0 | 129 | void ConfigurationFile::getServerConfiguration() |
| 13075593 | 1:5b6c5c2a33d0 | 130 | { |
| 13075593 | 1:5b6c5c2a33d0 | 131 | getIP(); |
| 13075593 | 1:5b6c5c2a33d0 | 132 | getMask(); |
| 13075593 | 1:5b6c5c2a33d0 | 133 | getGateway(); |
| 13075593 | 1:5b6c5c2a33d0 | 134 | getURL(); |
| 13075593 | 2:5af11ca8e085 | 135 | getBroadcastAddress(); |
| 13075593 | 1:5b6c5c2a33d0 | 136 | } |
| 13075593 | 1:5b6c5c2a33d0 | 137 | |
| 13075593 | 1:5b6c5c2a33d0 | 138 | void ConfigurationFile::getNodeConfiguration() |
| 13075593 | 1:5b6c5c2a33d0 | 139 | { |
| 13075593 | 1:5b6c5c2a33d0 | 140 | getIP(); |
| 13075593 | 1:5b6c5c2a33d0 | 141 | getMask(); |
| 13075593 | 1:5b6c5c2a33d0 | 142 | getGateway(); |
| 13075593 | 2:5af11ca8e085 | 143 | getBroadcastAddress(); |
| 13075593 | 0:1405a58a7e8d | 144 | } |
| 13075593 | 0:1405a58a7e8d | 145 | |
| 13075593 | 0:1405a58a7e8d | 146 | void ConfigurationFile::readConfigurationFile(char *pathName) |
| 13075593 | 0:1405a58a7e8d | 147 | { |
| 13075593 | 0:1405a58a7e8d | 148 | if (!cfg.read(pathName)) |
| 13075593 | 0:1405a58a7e8d | 149 | { |
| 13075593 | 0:1405a58a7e8d | 150 | error("Failure to read a configuration file.\n"); |
| 13075593 | 0:1405a58a7e8d | 151 | } |
| 13075593 | 0:1405a58a7e8d | 152 | } |