/*
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.Configuration.h
 * @ingroup	config
 * 
 * \brief The ScatterWeb.Configuration provides fuctions that allow you to
 * programmatically access configuration settings.
 * <p>
 * The configuration consists of the struct config_t defined in
 * ScatterWeb.Configuration.h. The variable Configuration is of that type and
 * represents the current config in RAM and can be accessed directly everytime.
 * <p>
 * Initial loading is done by Configuration_init() and
 * has to be called on initialization in main().
 * <p>
 * First time configuration:
 * Uncomment the following definition of firstTimeConfig and it will get layed
 * into Infomem (0x1000-0x1100, see .hex-File). Before Configuration_init()
 * loads the regular config from EEPROM, it checks if the first int (which
 * corresponds to the id) in Infomem is not 0xFFFF. If it is not, it copies the
 * configuration from Infomem to EEPROM (clearing Infomem afterwards and
 * loading the newly written data from EEPROM to Configuration).
 *
 * @version       $Rev: 509 $
 * @since         1.0
 *
 * $Id: ScatterWeb.Configuration.h 509 2008-02-05 14:45:22Z baar@PCPOOL.MI.FU-BERLIN.DE $
 */  

#ifndef ScatterWeb_Configuration
#define ScatterWeb_Configuration

/**
 @brief	If set device allows reprogramming itself.

 @see	#config_t:firmwareFlags

 @since	1.0
 */
#define FF_PROGRAMMABLE            (0x01)

/**
 @brief	If set dco adjusting will be enabled.

 @see	#config_t:firmwareFlags

 @since	1.0
 */
#define FF_DCOCHECKER              (0x02)

/**
 * @brief Node address
 * 
 * \note The node and network fields will be used to have separate logical networks
 * which in general do not accept messages from each other. Broadcasts will be limited
 * to the local subnet. The network address usually will be static for an application
 * and allows for different applications being developed mostly independently while being
 * in radio range.
 * Routing algorithms can use this addressing system for building clusters and explicitly
 * route packets between them.
 * <b>The neccessary application logic which provides this functionality is not yet implemented in the
 * transport layer.</b>
 *
 * @since 1.1
 * 
 */

/**
 * @brief	Node configuration structure
 *
 * The configuration is automatically loaded into Configuration at boot time and
 * stored when settings are changed through commands.
 *  
 * @see	Config_load, Config_save, Config_reset
 * @since         1.0
 */
typedef struct {
  netaddr_t	id;					///< this node's network address
  uint8_t		radio_txpower;		///< radio output power
  uint8_t		radio_channel;		///< radio channel (defined in radio driver)
  uint8_t		boot_logLevel;		///< initial loglevel (see #Debuglog_level, CMD_ASCII(bllv) )
  int16_t		sht11_tempdiff;		///< temperature reading offset in 1/100 °C
  uint8_t		firmwareFlags;		///< firmware configuration flags
} config_t;

/**
 @brief	Current node configuration

 @see	config_t

 @since	1.0
 */
extern config_t Configuration;

/**
 @brief		Initializes configuration settings for the configuration section.

 @return	<code>True</code> always.

 @since		1.0
 */
bool Configuration_init();

/**
 @brief	Prints configuration settings for the configuration section.

 @since	1.0
 */
void Configuration_print();

/**
 * @brief	Write the persistant configuration to infomemory
 * @since	1.1
 * @see		persistant_config_t
 */
void Configuration_save();

/**
 * @brief	Load the persistant configuration from infomemory
 * @return	true, if a valid configuration was loaded
 * @see		persistant_config_t
 * @since	1.1
 * 
 * A checksum is used to verify the configuration.
 */
bool Configuration_load();

/**
 * @brief	Load a default configuration
 * @since	1.1
 * \note:	The node's address is set to a random number in network 1.
 */
void Configuration_reset();

#endif
