Reputation: 26
Working on Small Embedded System in which am storing configurations in structure.
Now Suppose current config structure has 5 member and in future it will increase or decrease and in past might be it had 3 members only.
So while Upgrading and Downgrading Firmware it is getting difficult to read configurations because we dont know how many members will be there in structure.
please suggest way to handle
Upvotes: 1
Views: 521
Reputation: 3999
Definitely don't store your configuration as binary, such as a memory dump of a struct; this will get you into maintenance hell in the mid term. Recommended reading:
http://www.catb.org/esr/writings/taoup/html/textualitychapter.html
A common pattern is to store config data in INI style files, for which many plus one implementations exist for about every programming language in use, so no need to roll your own. Most config files in /etc
are a good example for this practice.
Upvotes: 0
Reputation: 44274
This can be done in several ways.
One approach is to store configuration values as key:value pairs. For instance:
"biasVoltage1":0.45
"biasVoltage2":0.52
"nextKey":value
First you initialize your struct members with default values. Then you read the key:value pairs one by one. If a key is known by running SW version, you parse the value and write it to the struct. If a key is unknown by running SW version, you ignore the value.
In this way each SW version will get exactly the configuration values it knows about (or a default value if a key is missing).
The keys doesn't have to be strings as indicated above. An alternative is to enumerate the keys.
Upvotes: 1