firmware/Temperature/src/Terminal.c
///////////////////////////////////////////////////////////////////////////////
/// \brief run the terminal command
///
///	\return TRUE success
///
///	\todo update the document return state value. need to implement
///////////////////////////////////////////////////////////////////////////////
\brief run the terminal command
\return TRUE success

\todo update the document return state value. need to implement
\ brief run the terminal command \ return TRUE success \ todo update the document return state value . need to implement
static int_fast8_t RunCommand(ListOfParameterStructureType *source)
{
	uint_fast16_t adcReading = 0;
	int32_t adcTempCelsius = 0;
	float adcNorm = 0.0;
	uint8_t message[25];
	enum {
		Command_LedControl = 1,
		Command_AdcOn = 2,
		Command_AdcOff = 3,
		Command_AdcSample = 4
	};
	SerialPort2.SendString((uint8_t*)"\r\n");
	switch ( source->List[0].Value.i32_t[0] )
	{
		case Command_LedControl: 
			if ( source->NumberOfParameter > 1 && source->List[1].Type == 'u') {
				if ( source->List[1].Value.i32_t[0] ) {
					Led_On();
				} else	{
					Led_Off();
				}
			} else {
				Led_Toggle();
			}
			break;
		case Command_AdcOn: 
			ADC_On();
			break;
		case Command_AdcOff: 
			ADC_Off();
			break;
		case Command_AdcSample: 
			if ( source->NumberOfParameter > 1 && source->List[1].Type == 'u') {
				if (ADC_Read(source->List[1].Value.i32_t[0], &adcReading )) {
					snprintf(&message[0], 25, "%d", adcReading);
					SerialPort2.SendString(&message[0]);
					SerialPort2.SendString((uint8_t*)"\r\n");
					adcTempCelsius = ADC_CalibratedTemperature(adcReading);
					snprintf(&message[0], 25, "%d", adcTempCelsius);
					SerialPort2.SendString(&message[0]);
					SerialPort2.SendString((uint8_t*)"C\r\n");
				} else {
					SerialPort2.SendString((uint8_t*)"Error reading ADC\r\n");
				}
				if (ADC_Normalize(adcReading, &adcNorm )) {
					uint32_t intpart = (uint32_t)adcNorm;
					uint32_t fracpart = (int32_t)((adcNorm - intpart) * 100000);
					snprintf(&message[0], 25, "%d.%05d", intpart, fracpart);
					SerialPort2.SendString(&message[0]);
					SerialPort2.SendString((uint8_t*)"\r\n");
				} else {
					SerialPort2.SendString((uint8_t*)"Error normalizing ADC readingr\n");
				}
					snprintf(&message[0], 25, "%d.%05d", intpart, fracpart);
					SerialPort2.SendString(&message[0]);
					SerialPort2.SendString((uint8_t*)"\r\n");
				} else {
					SerialPort2.SendString((uint8_t*)"Error reading ADC Norm\r\n");
				}
			}
			break;
		default:
			 undefined command
			return FALSE;
			break;
	}
	return TRUE;
}
static int_fast8_t RunCommand ( ListOfParameterStructureType * source ) { uint_fast16_t adcReading = 0 ; int32_t adcTempCelsius = 0 ; float adcNorm = 0.0 ; uint8_t message [ 25 ] ; enum { Command_LedControl = 1 , Command_AdcOn = 2 , Command_AdcOff = 3 , Command_AdcSample = 4 } ; SerialPort2 . SendString ( ( uint8_t * ) " \r \n " ) ; switch ( source -> List [ 0 ] . Value . i32_t [ 0 ] ) { case Command_LedControl : if ( source -> NumberOfParameter > 1 && source -> List [ 1 ] . Type == ' ' ) { if ( source -> List [ 1 ] . Value . i32_t [ 0 ] ) { Led_On ( ) ; } else { Led_Off ( ) ; } } else { Led_Toggle ( ) ; } break ; case Command_AdcOn : ADC_On ( ) ; break ; case Command_AdcOff : ADC_Off ( ) ; break ; case Command_AdcSample : if ( source -> NumberOfParameter > 1 && source -> List [ 1 ] . Type == ' ' ) { if ( ADC_Read ( source -> List [ 1 ] . Value . i32_t [ 0 ] , & adcReading ) ) { snprintf ( & message [ 0 ] , 25 , " " , adcReading ) ; SerialPort2 . SendString ( & message [ 0 ] ) ; SerialPort2 . SendString ( ( uint8_t * ) " \r \n " ) ; adcTempCelsius = ADC_CalibratedTemperature ( adcReading ) ; snprintf ( & message [ 0 ] , 25 , " " , adcTempCelsius ) ; SerialPort2 . SendString ( & message [ 0 ] ) ; SerialPort2 . SendString ( ( uint8_t * ) " \r \n " ) ; } else { SerialPort2 . SendString ( ( uint8_t * ) " \r \n " ) ; } if ( ADC_Normalize ( adcReading , & adcNorm ) ) { uint32_t intpart = ( uint32_t ) adcNorm ; uint32_t fracpart = ( int32_t ) ( ( adcNorm - intpart ) * 100000 ) ; snprintf ( & message [ 0 ] , 25 , " " , intpart , fracpart ) ; SerialPort2 . SendString ( & message [ 0 ] ) ; SerialPort2 . SendString ( ( uint8_t * ) " \r \n " ) ; } else { SerialPort2 . SendString ( ( uint8_t * ) " \n " ) ; } } break ; default : return FALSE ; break ; } return TRUE ; }
\brief run the terminal command
\return TRUE success
\ brief run the terminal command \ return TRUE success
// control the LED // Turn the ADC on // Turn the ADC off // Take a sample from the ADC // Split the decimal into the whole number and fraction since %f doesn't work with snprintf //				if (ADC_ReadNorm(source->List[1].Value.i32_t[0], &adcNorm )) { //					// Split the decimal into the whole number and fraction since %f doesn't work with snprintf //					uint32_t intpart = (uint32_t)adcNorm; //					uint32_t fracpart = (int32_t)((adcNorm - intpart) * 100000); // //					snprintf(&message[0], 25, "%d.%05d", intpart, fracpart); //					SerialPort2.SendString(&message[0]); //					SerialPort2.SendString((uint8_t*)"\r\n"); //				} else { //					SerialPort2.SendString((uint8_t*)"Error reading ADC Norm\r\n"); //				} // undefined command