/// @file config_vars.h
/// @brief read and store variables on the SD card
#ifndef CONFIG_VARS_H
#define	CONFIG_VARS_H
#include "cwgsys.h"
#include "pic24.h"

/// filename of configuration
#define CFG_FILE SYS_CONFIG_DFL
#define CFG_KEY_WIDTH_DFL 18
#define CFG_VAL_WIDTH_DFL 4

// TODO : if compiler is not optimizing out
// redundant strings, it may reduce memory
// footprint to assign these to (const char *) 
// variables

#define CFG_VERBOSE          "VERBOSE"
#define CFG_SERIAL_N         "SERIAL_N"
#define CFG_ECHO             "ECHO"
#define CFG_POWER_INIT       "POWER_INIT"
#define CFG_AUTO_OUT         "AUTO_OUT"
#define CFG_LICOR_MODEL      "LICOR_MODEL"
#define CFG_LICOR_TASK_EN    "LICOR_TASK_EN"
#define CFG_LICOR_PERIOD_MIN "LICOR_PERIOD_MIN"
#define CFG_UW_TASK_EN       "UW_TASK_EN"
#define CFG_UW_PERIOD_MIN    "UW_PERIOD_MIN"
#define CFG_UW_RATE          "UW_RATE"
#define CFG_VALVE_TYPE       "VALVE_TYPE"
#define CFG_STD_MOD          "STD_MOD"
#define CFG_EQU_SEC          "EQU_SEC"
#define CFG_AIR_SEC          "AIR_SEC"
#define CFG_ZERO_SEC         "ZERO_SEC"
#define CFG_STD_SEC          "STD_SEC"
#define CFG_PURGE_SEC        "PURGE_SEC"
#define CFG_VENT_SEC         "VENT_SEC"
#define CFG_TEL_XMIT_MIN     "TEL_XMIT_MIN"
#define CFG_TEL_RETRIES      "TEL_RETRIES"
#define CFG_ORBCOMM_TASK_EN  "ORBCOMM_TASK_EN"
#define CFG_TEL_MODE         "TEL_MODE "
#define CFG_TEL_PERIOD_MIN   "TEL_PERIOD_MIN "
#define CFG_PH_TASK_EN       "PH_TASK_EN"
#define CFG_PH_PERIOD_MIN    "PH_PERIOD_MIN"
#define CFG_PH_SCALE         "PH_SCALE"
#define CFG_OXY_TASK_EN      "OXY_TASK_EN"
#define CFG_OXY_PERIOD_MIN   "OXY_PERIOD_MIN"

/// @enum CFG_ECHO_t
/// @brief Configuration ECHO value enum
typedef enum{
    ECHO_NONE=0,
    ECHO_ALL=1,
    ECHO_CONS=2
}CFG_ECHO_t;

/// @brief Read config file and load values
/// @return ERR_FAILURE if it can't read file
return_code_t cfgLoad(void);
/// @brief get value of variable
/// @param str name of variable
/// @param [out] value pointer to where to put the value
/// @return ERR_FAILURE if variable name can't be found
return_code_t cfgGet(char* str, UINT16* value);
/// @brief quick check to see if a variable is zero or not
/// @param str name of variable to check
/// @return TRUE if found and is zero, FALSE if not found or not zero
int cfgIsZero(char* str);
/// @brief Set value of variable
/// @param str Name of variable
/// @param value New value for variable
/// @return ERR_FAILURE If variable name can't be found
return_code_t cfgSet(char* str, UINT16 value);
/// @brief Overwrites old config file with current values
/// @return ERR_FAILURE If file couldn't be written to
return_code_t cfgSave(void);
/// @brief fill a string with one variable-value pair, 
/// each call prints next pair.
/// @param [out] line buffer to store string
/// @return ERR_FAILURE if last pair reached, next call will be first pair
return_code_t cfgDumpLinew(char *line,int kw, int vw);

#define cfgDumpLine(p) cfgDumpLinew(p,CFG_KEY_WIDTH_DFL,CFG_VAL_WIDTH_DFL)

#endif	/// CONFIG_VARS_H 