Hi
Our codes are in fact equivalent.
uStrcpy (cValue, "Validate");
*usLengthToSend = 8;
is simply a bit riskier.
"Validate" is in fact a pointer to CHAR x[] = "Validate";
and (sizeof(x)-1) is 8.
The risk is that if you were to type in the length incorrectly - eg. 7 it would't be exactly correct and if you once edit the string and forget to change the length correctly it will also fail (slightly). Using the method which I use you can modify the string as you want without any risk of the code being broked.
[note that the insert string handling is performed in a case so there is no risk of chosing something which is already taken - it throws a compiler error and then simply try the next...]
To the sequence of changing and saving; I think that it is all working as I expect it to work after your modifications. I think that there are just some details about when things are changed in the temporary parameter buffer, when they are saved to FLASH in a the swap buffer, when the are validated in FLASH and when the program thinks that they are validated which is not exactly as you are expecting it to be.
I must admit that it is a bit complicated but the demo code is an example of how it could all be handled in a real project (because the demo is in fact also a real project...).
I think the things to be noted are:
1. The state validating is exists after a reset. It is only actually checked when loading the parameters from FLASH after a reset so just be changing (event saving to FLASH) you will never get the validating state which you are expecting - it needs the reset (unless you edit the state flag yourself;-) ).
2. When parameters are modified they are modified in RAM. There are two copies - a temporary version and a working version. Some modifications are made in the working version and so are immediately valid (eg. changing serial port speed - this is done on the fly). Some are changed in the temporary buffer but are not actually used yet. This is valid for IP address and MAC address etc. These can not normally be used immediately because otherwise your present connection would break down
[remember Windows before XP! After a network change you had to reboot! Even with XP it takes some time since the process is not that simple]. Therefore modifying the IP only prepares it to be saved in FLASH. Saving it saves it to FLASH but still doesn't apply it. Network changes are quite critical and we are back in Windows 3.11 teritory. Make a reset and then it is easy...
3. After the reset, the new settings are finally used, but they have been flagged as temporary settings (the old ones are also still in FLASH as well and so can be returned by simply deleting the temporary set - which happens after 3 minutes with no contact).
If you do want to save them to FLASH and reboot with them already fully operational (old ones have been overwritten!) then simply save them using
fnSaveNewPars(SAVE_NEW_PARAMETERS); rather than
fnSaveNewPars(SAVE_NEW_PARAMETERS_VALIDATE);
It may take a little study to grasp the complete concept but you should realise then why your project is responding as it is and then you can modify things as you wish them to be. (there are also some details in
http://www.utasker.com/docs/uTasker/uTaskerFileSystem.PDF from 9/14)
Last point.
In fact it is no problem to change IP on the fly if you really want to. Here's an example of how it can be done.
unsigned char newIPAddress[] = {192, 168, 1, 75};
temp_pars->temp_network.ucOurIP[0] = newIPAddress[0];
temp_pars->temp_network.ucOurIP[1] = newIPAddress[1];
temp_pars->temp_network.ucOurIP[2] = newIPAddress[2];
temp_pars->temp_network.ucOurIP[3] = newIPAddress[3];
fnSaveNewPars(SAVE_NEW_PARAMETERS);
uMemcpy(&network, &temp_pars->temp_network, sizeof(NETWORK_PARAMETERS));
fnDeleteArp();
This sets the new IP to the temporary structure.
It then saves the temporary structure to FLASH (this is valid also after next reset).
Then it copies from the temporary structure to the working structure (from this point IP, TCP etc. use it!!)
It is resommended to delete the ARP table since it will otherwise have entries which are possibly invalid for a new subnet.
The only thing which will cause troubles here is if it is change in an active connection (like via HTTP) since the connection will subsequently fail (the web server will probably show a blank page after a short time since it will time out).
This can also simply be avoided by not making the copy from temp_network to network immediately but rather starting a timer (say 2s). After the timer fires (the web page will have been served with the new details in the meantime) the copy can be effected. The browser has already closed the TCP connection in the meantime so no more error messages. But it will be necessary to connect the next time using the new address since the old one is no longer valid.
As you see, there should be no restrictions. However I still stick to the method with validation and timeouts since it ensures that no device is left stranded with invalid or unknown settings. Normally IP setup is not used a lot and so I prefer to play safe. Don't forget that you can use DHCP and there are various other network tricks allowing IP to be set
using ARP sequences and.... but that is another story!!
Cheers
Mark