text: /******************************************************************************
   * Copyright 2013-2014 Espressif Systems (Wuxi)
   *
   * FileName: user_main.c
   *
   * Description: entry file of user application
   *
   * Modification history:
   *     2014/1/1, v1.0 create this file.
  *******************************************************************************/
  #include "ets_sys.h"
  #include "osapi.h"
  
  #include "user_interface.h"
  
  #include "user_devicefind.h"
  #include "user_webserver.h"
  
  #if ESP_PLATFORM
  #include "user_esp_platform.h"
  #endif
  
  /******************************************************************************
   * FunctionName : user_rf_cal_sector_set
   * Description  : SDK just reversed 4 sectors, used for rf init data and paramters.
   *                We add this function to force users to set rf cal sector, since
   *                we don't know which sector is free in user's application.
   *                sector map for last several sectors : ABCCC
   *                A : rf cal
   *                B : rf init data
   *                C : sdk parameters
   * Parameters   : none
   * Returns      : rf cal sector
  *******************************************************************************/
  uint32 ICACHE_FLASH_ATTR
  user_rf_cal_sector_set(void)
  {
      enum flash_size_map size_map = system_get_flash_size_map();
      uint32 rf_cal_sec = 0;
  
      switch (size_map) {
          case FLASH_SIZE_4M_MAP_256_256:
              rf_cal_sec = 128 - 5;
              break;
  
          case FLASH_SIZE_8M_MAP_512_512:
              rf_cal_sec = 256 - 5;
              break;
  
          case FLASH_SIZE_16M_MAP_512_512:
          case FLASH_SIZE_16M_MAP_1024_1024:
              rf_cal_sec = 512 - 5;
              break;
  
          case FLASH_SIZE_32M_MAP_512_512:
          case FLASH_SIZE_32M_MAP_1024_1024:
              rf_cal_sec = 1024 - 5;
              break;
  
          default:
              rf_cal_sec = 0;
              break;
      }
  
      return rf_cal_sec;
  }
  
  void ICACHE_FLASH_ATTR
  user_rf_pre_init(void)
  {
  }
  
  /******************************************************************************
   * FunctionName : user_init
   * Description  : entry of user application, init user function here
   * Parameters   : none
   * Returns      : none
  *******************************************************************************/
  void ICACHE_FLASH_ATTR
  user_init(void)
  {
      os_printf("SDK version:%s\n", system_get_sdk_version());
  
  #if ESP_PLATFORM
      /*Initialization of the peripheral drivers*/
      /*For light demo , it is user_light_init();*/
      /* Also check whether assigned ip addr by the router.If so, connect to ESP-server  */
      user_esp_platform_init();
  #endif
      /*Establish a udp socket to receive local device detect info.*/
      /*Listen to the port 1025, as well as udp broadcast.
      /*If receive a string of device_find_request, it rely its IP address and MAC.*/
      user_devicefind_init();
  
      /*Establish a TCP server for http(with JSON) POST or GET command to communicate with the device.*/
      /*You can find the command in "2B-SDK-Espressif IoT Demo.pdf" to see the details.*/
      /*the JSON command for curl is like:*/
      /*3 Channel mode: curl -X POST -H "Content-Type:application/json" -d "{\"period\":1000,\"rgb\":{\"red\":16000,\"green\":16000,\"blue\":16000}}" http://192.168.4.1/config?command=light      */
      /*5 Channel mode: curl -X POST -H "Content-Type:application/json" -d "{\"period\":1000,\"rgb\":{\"red\":16000,\"green\":16000,\"blue\":16000,\"cwhite\":3000,\"wwhite\",3000}}" http://192.168.4.1/config?command=light      */
  #ifdef SERVER_SSL_ENABLE
      user_webserver_init(SERVER_SSL_PORT);
  #else
      user_webserver_init(SERVER_PORT);
  #endif
  }
  
  