 /********************************************************

	EG2100_Var.c
	2001, Z-World

	Example of a target board creating a web page with
	variables while connected to a EG2100 RabbitLink
	board.

	This program demonstrates the ability of a Rabbit-
	based target board to update files and variables on
	the web server of the RabbitLink board it is
	connected to.
	
 ********************************************************/

#define	CTRL_D	0x04

main()
{
	long starttime;

	long oldseconds;
	long seconds;
	char strvar[50];
	float floatvar;

	// Record the time at which the program started
	starttime = MS_TIMER;

	// Initialize the variables
	oldseconds = 0;
	seconds = 0;
	strcpy(strvar, "Good bunny.");
	floatvar = 42.42;

	// Enable all STDIO to go to the RabbitLink console
	PrintToConsole(1);

	// Make sure we are not in the middle of a command
	printf("\r\n");

 	// Delete the web page if it exists
	printf("delete variable.shtml\r\n");

	// Reset the variables
	printf("reset variables\r\n");
	printf("y\r\n");

	// Create the web page
	printf("put variable.shtml\r\n");
	printf("<HTML>\r\n");
	printf("<HEAD>\r\n");
	printf("<TITLE>Web Variable Demonstration Page</TITLE>\r\n");
	printf("</HEAD>\r\n");
	printf("<BODY>\r\n");
	printf("<H1>Web Variable Demonstration Page</H1>\r\n");
	printf("It has been <!--#echo var=\"seconds\"--> seconds since\r\n");
	printf("this program has started.\r\n");
	printf("<P>\r\n");
	printf("Here's a string test: <!--#echo var=\"string\"-->\r\n");
	printf("<P>\r\n");
	printf("And a floating point test: <!--#echo var=\"float\"-->\r\n");
	printf("</BODY>\r\n");
	printf("</HTML>\r\n");
	
	// End the web page
	printf("%c", CTRL_D);

	// Create the variables
	printf("createv seconds INT32 \"%%ld\" %ld\r\n", seconds);
	printf("createv string STRING \"%%s\" \"%s\" 50\r\n", strvar);
	printf("createv float FLOAT32 \"%%.2f\" %f\r\n", floatvar);

	// Stop all STDIO from going to the RabbitLink console
	PrintToConsole(0);

	while (1) {
		// Update the variable only if 10 seconds have passed
		seconds = (MS_TIMER - starttime) / 1000;
		if (((seconds % 10) == 0) && (seconds > oldseconds)) {
			oldseconds = seconds;
			PrintToConsole(1);
			// Update the variable
			printf("putv seconds %ld\r\n", seconds);
			PrintToConsole(0);
		}
	}
}
