/*
Copyright 2007, Freie Universitaet Berlin. All rights reserved.

These sources were developed at the Freie Universität Berlin, Computer
Systems and Telematics group.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

- Neither the name of Freie Universitaet Berlin (FUB) nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

This software is provided by FUB and the contributors on an "as is"
basis, without any representations or warranties of any kind, express
or implied including, but not limited to, representations or
warranties of non-infringement, merchantability or fitness for a
particular purpose. In no event shall FUB or contributors be liable
for any direct, indirect, incidental, special, exemplary, or
consequential damages (including, but not limited to, procurement of
substitute goods or services; loss of use, data, or profits; or
business interruption) however caused and on any theory of liability,
whether in contract, strict liability, or tort (including negligence
or otherwise) arising in any way out of the use of this software, even
if advised of the possibility of such damage.

This implementation was developed by the CST group at the FUB.

For documentation and questions please use the web site
http://scatterweb.mi.fu-berlin.de and the mailinglist
scatterweb@lists.spline.inf.fu-berlin.de (subscription via the Website).
Berlin, 2007
*/

/**
 @file		ScatterWeb.Data.h
 @ingroup	kernel
 @brief		The ScatterWeb.Data consists mostly of the fuctions that constitute the sensors architecture.
 @version	$Revision: 348 $
 @since		1.0
 @author	Marco Hutta

 The sensors architecture enables you to build components that efficiently
 manage data from multiple data sources. It provides the tools to initialize,
 enable, and disable data in this multiple tier system.

 $Id: ScatterWeb.Data.h 348 2007-12-13 12:00:19Z hutta@PCPOOL.MI.FU-BERLIN.DE $
 */

/**
 @ingroup kernel
 @{
 */

#ifndef ScatterWeb_Data
#define ScatterWeb_Data

/**
 * @brief	Holds sensor data record.
 * @since	1.0
 */
typedef struct {
	uint8_t board; 			///< id of board
	uint8_t channel; 		///< channel of sensors
	time_t timeStamp; 		///< timestamp of sensor reading
	uint8_t value_length; 	///< length of value
	uint8_t* value; 		///< raw value of sensor reading
} sdata_t;

/**
 * @brief	Copy of the sensor data record.
 * @since	1.0
 */
sdata_t Data_sensorValue;

/**
 * @brief	Copy of the sensor event data record.
 * @since	1.0
 */
sdata_t Data_sensorEventValue;

/**
 * @brief	Copy of the sensor data stream.
 * @since	1.0
 */
uint8_t Data_sensorStream[6];

/**
 * @brief	Copy of the sensor event data stream.
 * @since	1.0
 */
uint8_t Data_sensorEventStream[1];

/**
 * @brief	Copy of the board ID.
 * @since	1.0
 */
uint8_t Data_boardID;

/**
 * @brief	Copy of the channels.
 * @since	1.0
 */
uint8_t Data_channels;

/**
 * @brief		Initializes the sensors.
 * @param[in]	driver	driver for initializing
 * @return		<code>True</code> always.
 * @since		1.0
 */
bool Data_init(fp_vp driver);

/**
 * @brief	Returns board ID.
 * @return	ID of the sensor board<br>
 *			0  - this means that no sensor board is available<br>
 *			1  - this means that just on-board sensors are available<br>
 *			>1 - otherwise<br>
 * @since	1.0
 */
uint8_t Data_getBoardID();

/**
 * @brief	Returns channels.
 * @return	number of channels<br>
 *			0  - this means that no sensor is available<br>
 *			>0 - otherwise<br>
 * @since	1.0
 */
uint8_t Data_getChannels();

/**
 * @brief		Starts a sensor.
 * @param[in]	channel				sensor to start
 * @param[in]	parameter_length	length of paraemter
 * @param[in]	parameter			parameter to pass
 * @return		<code>True</code> if successful<br>
 *				<code>False</code> otherwise.
 * @since		1.0
 */
bool Data_enable(uint8_t channel, uint8_t parameter_length, uint8_t* parameter);

/**
 * @brief		Stops a sensor.
 * @param[in]	channel	sensor to stop
 * @return		<code>True</code> if successful;<br>
 *				<code>False</code> otherwise.
 * @since		1.0
 */
bool Data_disable(uint8_t channel);

/**
 * @brief		Reads a sensor.
 * @param[in]	channel	sensor to read (see \ref Channel)
 * @return		value of sensor reading.<br>
 *				error: sdata_t.channel = 255
 * @since		1.0
 */
sdata_t Data_read(uint8_t channel);

/**
 * @brief		Registers a driver.
 * @param[in]	enableFunc	driver for enableling
 * @param[in]	disableFunc	driver for disableling
 * @param[in]	readFunc	driver for reading
 * @return		<code>True</code> if successful;<br>
 *				<code>False</code> otherwise.
 * @since		1.0
 */
bool Data_registerDriver(fp_vp enableFunc, fp_vp disableFunc, fp_vp readFunc);

#endif

/** @} */
