/**
 @brief	Replace HTML's variables to system configuration value
*/
static uint16_t replace_sys_env_value(
	uint8_t* base, 	/**< pointer to html buffer */
	uint16_t len
	)
{
	uint8_t sys_string[16]; // if there are more characters to substituted in response file, then make this bigger
	uint8_t *tptr, *ptr;
	time_t time_stamp;
	tm local_time;

	tptr = ptr = base;

	while((ptr = (uint8_t*)strchr((char*)tptr, '$')))
	{
		if((tptr = (uint8_t*)strstr((char*)ptr, EVB_PAGES_SERVED)))
		{
			memset(tptr,0x20,14); // erase system variable trigger string
			if( eeprom_is_ready() )
				sprintf_P((char *)sys_string, PSTR("%08u"), eeprom_read_dword(&pagesServed) ); // number of pages served by the http server.
			memcpy(tptr,sys_string,8); // copy the characters, but don't copy the /0
			tptr+=8;
		}

#if defined (portRTC_DEFINED)
		else if((tptr = (uint8_t*)strstr((char*)ptr, EVB_RTC)))
		{
			memset(tptr,0x20,11); // erase system variable trigger string
			if ( getDateTimeDS1307( (tm*)&local_time ) == pdTRUE)
				sprintf_P((char *)sys_string, PSTR("%02u:%02u:%02u"), local_time.tm_hour, local_time.tm_min, local_time.tm_sec);
			memcpy(tptr,sys_string,8);  // copy the characters, but don't copy the /0
			tptr+=8;
		}
#else
		else if((tptr = (uint8_t*)strstr((char*)ptr, EVB_RTC)))
		{
			memset(tptr,0x20,11); // erase system variable trigger string
	    	time(&time_stamp);
	    	localtime_r( &time_stamp, &local_time);
			sprintf_P((char *)sys_string, PSTR("%02d:%02d:%02d"), local_time.tm_hour, local_time.tm_min, local_time.tm_sec);
			memcpy(tptr,sys_string,8);  // copy the characters, but don't copy the /0
			tptr+=8;
		}
#endif
		else	// tptr == 0 && ptr!=0;
		{
			if(ptr==base)
			{
//				xSerialPrint_P(PSTR("$ Character"));
				return len;
			}
//			xSerialPrint_P(PSTR("REPLACE CONTINUE"));
			tptr = ptr;
			break;
		}
	}
	if(!ptr) return len;
	return (uint16_t)(tptr-base);
}
Example #2
0
static void TaskWriteLCD(void *pvParameters) // Write to LCD
{
    (void) pvParameters;

    TickType_t xLastWakeTime;
	/* The xLastWakeTime variable needs to be initialised with the current tick
	count.  Note that this is the only time we access this variable.  From this
	point on xLastWakeTime is managed automatically by the vTaskDelayUntil()
	API function. */
	xLastWakeTime = xTaskGetTickCount();

	uint8_t temperature_print; // true if temperature can be displayed.

    eeprom_read_block(&xMaximumTempTime, &xMaximumEverTempTime, sizeof(xRTCTempArray));
    eeprom_read_block(&xMinimumTempTime, &xMinimumEverTempTime, sizeof(xRTCTempArray));

    lcd_Init();	// initialise LCD, move cursor to start of top line

    while(1)
    {
    	if(getDateTimeDS1307(&xCurrentTempTime.DateTime))
    	{
			if ( (xCurrentTempTime.Temperature = ReadADCSensors())) // if non 0 then a reading returned.
			{	// trigger a temperature reading

				temperature_print = true;
				xCurrentTempTime.Temperature -= 273.15; // Convert from Kelvin to Celcius

				if( (xCurrentTempTime.Temperature < 65) && (xCurrentTempTime.Temperature > xMaximumTempTime.Temperature)) // check for maximum temp
				// we don't expect the temperature sensor to work above 65C
				{
					xMaximumTempTime = xCurrentTempTime;

					// Now we commit the time and temperature to the EEPROM, forever...
					eeprom_update_block(&xMaximumTempTime, &xMaximumEverTempTime, sizeof(xRTCTempArray));
				}

				if( (xCurrentTempTime.Temperature > (-30)) && (xCurrentTempTime.Temperature < xMinimumTempTime.Temperature)) // and check for minimum temp
				// we don't expect the temperature sensor to work below -30C
				{
					xMinimumTempTime = xCurrentTempTime;

					// Now we commit the time and temperature to the EEPROM, forever...
					eeprom_update_block(&xMinimumTempTime, &xMinimumEverTempTime, sizeof(xRTCTempArray));
				}
			}
			else temperature_print = false;

			lcd_Locate(0, 0);  // go to the first character of the first LCD line
			switch( xCurrentTempTime.DateTime.tm_wday )
			{
				case SUNDAY:
					lcd_Print_P(PSTR("Sunday   "));
					break;
				case MONDAY:
					lcd_Print_P(PSTR("Monday   "));
					break;
				case TUESDAY:
					lcd_Print_P(PSTR("Tuesday  "));
					break;
				case WEDNESDAY:
					lcd_Print_P(PSTR("Wednesday"));
					break;
				case THURSDAY:
					lcd_Print_P(PSTR("Thursday "));
					break;
				case FRIDAY:
					lcd_Print_P(PSTR("Friday   "));
					break;
				case SATURDAY:
					lcd_Print_P(PSTR("Saturday "));
					break;
				default:
					lcd_Print_P(PSTR("NotMyDay "));
					break;
			}

			// display Day Date/Month/Year
			lcd_Locate(0, 10);              // go to the eleventh character of the first LCD line
			lcd_Printf_P( PSTR("%2u/%2u/%4u"), xCurrentTempTime.DateTime.tm_mday, xCurrentTempTime.DateTime.tm_mon, (xCurrentTempTime.DateTime.tm_year + 1900) );

			// display the current temperature
			lcd_Locate(1, 1);			// LCD cursor to third character of the second LCD line
			if ( temperature_print )	// print the temperature if you got it
				lcd_Printf_P( PSTR("%6.2f"), xCurrentTempTime.Temperature); // print Celcius temperature

			// display the current time
			lcd_Locate(1, 9);             // go to the ninth character of the second LCD line
			lcd_Printf_P(PSTR("%2u:%02u:%02u"),xCurrentTempTime.DateTime.tm_hour, xCurrentTempTime.DateTime.tm_min, xCurrentTempTime.DateTime.tm_sec);

			// display the maximum temperature, time and date
			lcd_Locate(2, 0);          // go to the first character of the third LCD line
			lcd_Printf_P(PSTR("Max%5.1f"),xMaximumTempTime.Temperature);			// print the maximum temperature value

			lcd_Locate(2, 9);          // go to the ninth character of the third LCD line
			lcd_Printf_P(PSTR("%2u:%02u %2u/%2u"),xMaximumTempTime.DateTime.tm_hour, xMaximumTempTime.DateTime.tm_min, xMaximumTempTime.DateTime.tm_mday, xMaximumTempTime.DateTime.tm_mon );

			// display the m temperature, time and date
			lcd_Locate(3, 0);          // go to the first character of the forth LCD line
			lcd_Printf_P(PSTR("Min%5.1f"),xMinimumTempTime.Temperature);			// print the minimum temperature value

			lcd_Locate(3, 9);          // go to the ninth character of the fourth LCD line
			lcd_Printf_P(PSTR("%2u:%02u %2u/%2u"),xMinimumTempTime.DateTime.tm_hour, xMinimumTempTime.DateTime.tm_min, xMinimumTempTime.DateTime.tm_mday, xMinimumTempTime.DateTime.tm_mon );

			if(xCurrentTempTime.DateTime.tm_sec == 0)
			// resume the xTaskWriteRTCRetrograde() task, now that we need to write the analogue hands.
				vTaskResume( xTaskWriteRTCRetrograde );
    	}
//		xSerialPrintf_P(PSTR("LCD: Stack HighWater @ %u\r\n"), uxTaskGetStackHighWaterMark(NULL));
        vTaskDelayUntil( &xLastWakeTime, ( 200 / portTICK_PERIOD_MS ) );
	}
}
Example #3
0
static void TaskMonitor(void *pvParameters) // Monitor for Serial Interface
{
    (void) pvParameters;

	uint8_t *ptr;
	int32_t p1;

	// create the buffer on the heap (so they can be moved later).
	if(LineBuffer == NULL) // if there is no Line buffer allocated (pointer is NULL), then allocate buffer.
		if( !(LineBuffer = (uint8_t *) pvPortMalloc( sizeof(uint8_t) * LINE_SIZE )))
			xSerialPrint_P(PSTR("pvPortMalloc for *LineBuffer fail..!\r\n"));


    while(1)
    {
    	xSerialPutChar(&xSerialPort, '>');

		ptr = LineBuffer;
		get_line(ptr, (uint8_t)(sizeof(uint8_t)* LINE_SIZE)); //sizeof (Line);

		switch (*ptr++) {

		case 'h' : // help
			xSerialPrint_P( PSTR("rt - reset maximum & minimum temperatures\r\n") );
			xSerialPrint_P( PSTR("t  - show the time\r\n") );
			xSerialPrint_P( PSTR("t  - set the time\r\nt [<year yy> <month mm> <date dd> <day: Sun=0> <hour hh> <minute mm> <second ss>]\r\n") );
			break;

#ifdef portRTC_DEFINED
		case 't' :	/* t [<year yy> <month mm> <date dd> <day: Sun=0> <hour hh> <minute mm> <second ss>] */

			if (xatoi(&ptr, &p1)) {
				SetTimeDate.tm_year = (uint8_t)p1 + 100; 			// convert to (Gregorian - 1900)
				xatoi(&ptr, &p1); SetTimeDate.tm_mon = (uint8_t)p1;
				xatoi(&ptr, &p1); SetTimeDate.tm_mday = (uint8_t)p1;
				xatoi(&ptr, &p1); SetTimeDate.tm_wday = (uint8_t)p1;
				xatoi(&ptr, &p1); SetTimeDate.tm_hour = (uint8_t)p1;
				xatoi(&ptr, &p1); SetTimeDate.tm_min = (uint8_t)p1;
				if (!xatoi(&ptr, &p1))
					break;
				SetTimeDate.tm_sec = (uint8_t)p1;

				xSerialPrintf_P(PSTR("Set: %u/%u/%u %2u:%02u:%02u\r\n"), SetTimeDate.tm_year, SetTimeDate.tm_mon, SetTimeDate.tm_mday, SetTimeDate.tm_hour, SetTimeDate.tm_min, SetTimeDate.tm_sec);
				if (setDateTimeDS1307( &SetTimeDate ) == pdTRUE)
					xSerialPrint_P( PSTR("Setting successful\r\n") );

			} else {

				if (getDateTimeDS1307( &xCurrentTempTime.DateTime) == pdTRUE)
					xSerialPrintf_P(PSTR("Current: %u/%u/%u %2u:%02u:%02u\r\n"), xCurrentTempTime.DateTime.tm_year + 1900, xCurrentTempTime.DateTime.tm_mon, xCurrentTempTime.DateTime.tm_mday, xCurrentTempTime.DateTime.tm_hour, xCurrentTempTime.DateTime.tm_min, xCurrentTempTime.DateTime.tm_sec);
			}
			break;
#endif

		case 'r' : // reset
			switch (*ptr++) {
			case 't' : // temperature

				xMaximumTempTime = xCurrentTempTime;
				xMinimumTempTime = xCurrentTempTime;
				// Now we commit the time and temperature to the EEPROM, forever...
				eeprom_update_block(&xMaximumTempTime, &xMaximumEverTempTime, sizeof(xRTCTempArray));
				eeprom_update_block(&xMinimumTempTime, &xMinimumEverTempTime, sizeof(xRTCTempArray));
				break;

			default :
				break;
			}
			break;

		default :
			break;
		}
// 		xSerialPrintf_P(PSTR("\r\nSerial Monitor: Stack HighWater @ %u"), uxTaskGetStackHighWaterMark(NULL));
//		xSerialPrintf_P(PSTR("\r\nFree Heap Size: %u\r\n"), xPortGetMinimumEverFreeHeapSize() ); // needs heap_1, heap_2 or heap_4 for this function to succeed.

    }

}