Hi All
Here is an additional 'practical' guide to adding some simple strings. It is very easy to do but can already start performing useful things...
Regards
Mark
1) The use of the pound sign as control character:
The good thing about this is that Browsers don’t display it, even if it is put at bad locations – one less fortunate thing is that a US keyboard doesn't actually have it on it...! However it doesn’t have to be this – it can be any other which doesn’t normally appear in text and HTML commands. See config.h
#define WEB_PARAMETER_GENERATION // support of parameter generating (eg. manipulating select and adding values)
#define WEB_PARAMETER_HANDLING // support handling of received web parameters
#define WEB_PARSER_START '£' // this symbol is used in Web pages to instruct parsing to begin
#define WEB_INSERT_STRING 'v'
#define WEB_DISABLE_FIELD 'D'
#define WEB_NOT_DISABLE_FIELD 'd'
#define WEB_SELECTED_FIELD 's'
#define WEB_INSERT_DYNAMIC 'H'
//#define WEB_ESCAPE_LEN 5 // defaults to 4 if not defined
As you see, you can define all control characters as you feel fit. This will at least overcome the problem of the missing key.
2. To get you going on parsing here is a more detailed example.
I suggest that you even remove all content of fnInsertString() since it is quite large in the demo and, although case statements help (in comparison) to if () {} else if{} else if{} at some point they do get rather big and then it can be difficult to get your bearings.
3. In an HTML file simply try the following.
I assume here that you change the pound sign to the dollar sign [define WEB_PARSER_START '$'] (beware that you would however not be able to use the dollar sign in text of it were really chosen – you can decide the best for yourself – the others remain as they are).
Hello my name is $vMB {these are my initials but you can use your own if you like and change the use below}
Load this HTML file to the board (or better the simulator). If you view the page it will simply display this: “Hello my name is $vMB”
However the routine fnInsertString() will have been called due to the fact that the parser had found the sequence $v – it then passes parameters “MB” to the routine. Initially it doesn't do anything and lets the control sequence through.
4. Now edit fnInsertString() as follows:
#define MAX_SIMPLE_INSERT 100 // depends on you maximum content
static CHAR cValue[MAX_SIMPLE_INSERT]; // space to hold statistic string !!Must be static!!!
CHAR *cPtr = 0;
if (*ptrBuffer++ == 'M') {
static const CHAR Mark[] = "Mark Butcher";
uStrcpy(cValue, Mark);
*usLengthToSend = (sizeof(Mark) - 1);
}
return cValue;
When this now runs it will serve the following: “Hello my name is Mark Butcher” {or your own name if you have inserted it instead}
The routine above has simply interpreted the ‘M’ to know that it needs to insert the string. It could also use the following ‘B’ to distinguish sub-decisions (like name of wife MW, or of child MC etc.). Also the length of the interpreter sequence can be increased by defining a longer value of WEB_SCAPE_LEN (but it is very rare that two characters is not enough (62 x 62 possibilities already gives 3’844 decisions) – but sometimes it does help to be able to use less cryptic values… As you see, the handler is in fact not that complicated but can of course grow with increased number of permutations (then it is up to the programmer to keep it well managed so that he/she doesn’t get lost as work increases).
Note that values (eg. ADC values) can be displayed – simply insert the value into the string – eg.
else if ("A") { // an ADC value is to be displayed
static const unsigned short usADC[8] = {1,2,3,4,5,6,7,8}; // test values
unsigned char ucADC = (*ptrBuffer - '0'); // which input is to be displayed? (0..7)
if (ucADC < 8 ) { // check valid range
fnBufferHex(usADC[ucADC], (sizeof(usADC[0]) | WITH_LEADIN), cValue); // insert string value in HEX
*usLengthToSend = 6; // 0x0000 - fixed string length
}
}
This uses fixed values for test purposes but could be real values from registers.
In the HTML file simply edit
Hello my name is $vMB<br>
ADC0 = $vA0<br>
ADC1 = $vA1<br>
ADC2 = $vA2<br>
ADC3 = $vA3<br>
ADC4 = $vA4<br>
ADC5 = $vA5<br>
ADC6 = $vA6<br>
ADC7 = $vA7<br>
Load the page and (with the second test code above) the web page now looks like:
Hello may name is Mark Butcher
ADC0 = 0x0001
ADC1 = 0x0002
ADC2 = 0x0003
ADC3 = 0x0004
ADC4 = 0x0005
ADC5 = 0x0006
ADC6 = 0x0007
ADC7 = 0x0008
5. Now add your own extensions display the data that you would like to see
... good luck!!