/********************************* (C) РОТЕК ***********************************
 * @module  bt_6701_settings
 * @file    bt_6701_settings.c
 * @version 1.0.0
 * @date    XX.XX.XXXX
 * $brief   bt_6701_settings
 *******************************************************************************
 * @history     Version  Author         Comment
 * XX.XX.XXXX   1.0.0    Telenkov D.A.  First release.
 *******************************************************************************
 */

#include "stm32f4xx.h"  
#include "common_config.h"
#include "bt_6701_settings.h"
#include "settings_api.h"
#include "common_config.h"
#include "sys_api.h"

#include "FreeRTOS.h"
#include "task.h"

#include <string.h>
#include <stdlib.h>


/**
  * @brief  Общая структура настроек
  */
extern SETTINGS_t sSettings;

char * SETTINGS_GetTestState(void)
{
	return sSettings.sFlags.testState;
}

/**
  * @brief
  */
void SETTINGS_SetTest(char *state)
{
	SYS_t *sSys = NULL;

	sSys = pvPortMalloc(sizeof(*sSys));
	if (sSys) {
	  SYS_Load(sSys);
	  strcpy(sSys->testState, state);
	  SYS_Save(sSys);
	  vPortFree(sSys);
	  SETTINGS_Save();
	}
}

/**
  * @brief  Устанавливает Serno, но не сохраняет новые настройки во флеш
  */
void SETTINGS_SetSerno(char *serno)
{
	SYS_t *sSys = NULL;

	sSys = pvPortMalloc(sizeof(*sSys));
	if (sSys) {
	  SYS_Load(sSys);
	  strcpy(sSys->serial, serno);
	  strcpy(sSettings.sInfo.serialNumber, sSys->serial);
	  SYS_Save(sSys);
	  vPortFree(sSys);
	  SETTINGS_Save();
	}
}

/**
  * @brief  Устанавливает mac, но не сохраняет новые настройки во флеш
  */
void SETTINGS_SetMac(char *mac)
{
	SYS_t *sSys = NULL;

	sSys = pvPortMalloc(sizeof(*sSys));
	if (sSys) {
	  SYS_Load(sSys);
	  strcpy(sSys->mac, mac);
	  strcpy(sSettings.sInfo.mac, sSys->mac);
	  SYS_Save(sSys);
	  vPortFree(sSys);
	  SETTINGS_Save();
	}
}


/**
  * @brief  Установить параметры сетевого подключения по умолчанию
  */
void Service_SETTINGS_SetWebParamsDef(void)
{
#ifdef HARDWARE_BT6706
	  strcpy(sSettings.sWebParams.ip, "192.168.0.6");
#elif HARDWARE_BT6702
	  strcpy(sSettings.sWebParams.ip, "192.168.0.2");
#endif
	  strcpy(sSettings.sWebParams.gate, "192.168.0.1");
	  strcpy(sSettings.sWebParams.mask, "255.255.255.0");
	  sSettings.sWebParams.dhcpEnable = 1;
}

/**
  * @brief  Установить временные параметры сетевого подключения по умолчанию
  */
void Service_SETTINGS_SetTempWebParamsDef(void)
{
#ifdef HARDWARE_BT6706
	  strcpy(sSettings.sWebTempParams.ip, "192.168.0.6");
#elif HARDWARE_BT6702
	  strcpy(sSettings.sWebTempParams.ip, "192.168.0.2");
#endif
	  strcpy(sSettings.sWebTempParams.gate, "192.168.0.1");
	  strcpy(sSettings.sWebTempParams.mask, "255.255.255.0");
	  sSettings.sWebTempParams.dhcpEnable = 1;
}






/********************************* (C) РОТЕК **********************************/    
