Example #1
0
/**
  * @brief  Initialize the middleware libraries and stacks
  * @param  None
  * @retval None
  */
void MOD_LibInit(void)
{
  NVIC_InitTypeDef NVIC_InitStructure;

  MOD_GetParam(GLOBAL_SETTINGS_MEM , &Global_Config.d32);

  /* Force settings change to apply them */
  Global_Config.b.Configuration_Changed = 1;

  /* Starting USB Init. Process */
  GL_State_Message((uint8_t *)"USB Host Starting.  ");

  /*Init USB Host */
  USBH_Init(&USB_OTG_Core,
            USB_OTG_FS_CORE_ID,
            &USB_Host,
            &USBH_MSC_cb,
            &USBH_USR_cb);

  GL_State_Message((uint8_t *)"USB Host Started.");

  GL_State_Message((uint8_t *)"RTC and backup Starting.  ");
  /* Init RTC and Backup */
  if ( RTC_Configuration() == 0)
  {
    GL_State_Message((uint8_t *)"RTC and backup Started.");
    CONSOLE_LOG((uint8_t *)"[SYSTEM] RTC and backup Started.");
  }
  else
  {
    GL_State_Message((uint8_t *)"ERR : RTC could not be started.");
    CONSOLE_LOG((uint8_t *)"[ERR] RTC start-up FAILED .");
  }

  NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

  SD_Init();

  if ( f_mount( 1, &MSD_fatfs ) != FR_OK )
  {
    /* fatfs initialisation fails*/
    CONSOLE_LOG((uint8_t *)"[FS] Cannot initialize FS on drive 1.");
  }
  else
  {
    CONSOLE_LOG((uint8_t *)"[FS] FS on drive 1 initialized.");
  }
}
Example #2
0
static int start_update_download(struct update_context *ctx, const char *url) {
  CONSOLE_LOG(LL_INFO, ("Updating FW"));

  if (do_http_connect(ctx, url) < 0) {
    ctx->status_msg = "Failed to connect update server";
    return -1;
  }

  return 1;
}
Example #3
0
	MySQLp::MySQLp(const DataBaseHost &host)
		:is_good_connection_(false), host_(host)
	{
		reconnect_flag_ = 1;//1表示自动重连 0表示不自动重连

		mysql_init(&mysql_);
		mysql_options(&mysql_,MYSQL_OPT_RECONNECT, &reconnect_flag_);

		if (mysql_real_connect(&mysql_, host_.ip_.c_str(), host_.usr_.c_str(), host_.pwd_.c_str(), host_.dbname_.c_str(), host_.port_, 0, 0))
		{
			is_good_connection_ = true;
			//INDEX_EVENT("MySQLp::Conect() Connect Succeed ");
			//INDEX_EVENT("MySQLp::Conect() IP = " << host_.ip_);
		}
		else
		{
			CONSOLE_LOG("MySQLp::Conect() Connect Failed");
			CONSOLE_LOG("MySQLp::Conect() IP = " << host_.ip_ << "\tport = " << host_.port_);
		}
	}
Example #4
0
/**
* @brief  Inititialize the target hardware.
* @param  None
* @retval None
*/
uint32_t BSP_Init (void)
{
  /* Initialize the LEDs */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);  

  CONSOLE_LOG((uint8_t *)"[SYSTEM] Data RAM Init : OK.");
  /* Initialize the LCD */
  GL_LCD_Init();
  CONSOLE_LOG((uint8_t *)"[SYSTEM] LCD Init : OK.");
  /* Initialize the TSC */
  GL_TSC_Init();
  CONSOLE_LOG((uint8_t *)"[SYSTEM] Touchscreen Init : OK.");
  /* Initialize the Joystick */
  GL_JOY_Init();
  CONSOLE_LOG((uint8_t *)"[SYSTEM] Joystick Init : OK.");
  /* Initialize the PSRAM */
  SRAM_Init();
  CONSOLE_LOG((uint8_t *)"[SYSTEM] SRAM Init: OK.");

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_BKPSRAM, ENABLE);
  CONSOLE_LOG((uint8_t *)"[SYSTEM] BKPSRAM Init : OK.");

  SYSCFG_CompensationCellCmd(ENABLE);

  /* Enable RNG clock source */
  RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE);

  /* RNG Peripheral enable */
  RNG_Cmd(ENABLE);

  return 0;
}
Example #5
0
/**
  * @brief  Add a module in the module's list
  * @param  module: module structure pointer
  * @param  group: group that the module belong to  
  * @retval Status
  */
uint8_t  MOD_AddModule(MOD_InitTypeDef *module, uint8_t group)
{
  uint8_t idx = 0;
  char temp[40];

  /* check for id unicity */
  for ( ; idx < MOD_table[group].counter ; idx ++)
  {
    if (MOD_table[group].module[idx]->id == module->id)
    {
      sprintf(temp, "ERROR : %s module cannot be loaded", MOD_table[group].module[idx]->name);
      CONSOLE_LOG((uint8_t *)temp);
      return 1;
    }
  }
  MOD_table[group].module[MOD_table[group].counter] = module;
  MOD_table[group].counter ++;
  sprintf(temp, "[SYSTEM] %s module v%d.%d.%d loaded.",
          MOD_table[group].module[idx]->name,
          HIBYTE(MOD_table[group].module[idx]->rev) , LOBYTE(MOD_table[group].module[idx]->rev) >> 4, MOD_table[group].module[idx]->rev & 0xF );

  CONSOLE_LOG((uint8_t *)temp);
  return 0;
}
void ContentQuotaScheduler::ReloadConfig(ContentManagerCfg *m_inconfig, bool is_started)
{
    max_daily_rid_num = m_inconfig->CONTENT_RIDS_DAILY_NUM;
    max_minute_rid_num = m_inconfig->CONTENT_RIDS_MINUTE_NUM;
    pause_time_start = m_inconfig->CONTENT_PAUSE_START_TIME;
    pause_time_end = m_inconfig->CONTENT_PAUSE_END_TIME;
    if (true == is_started) {
        LOG4CPLUS_INFO(g_logger, "Scheduler: config reloaded, daily_cap "<< max_daily_rid_num
            << " minute_cap " << max_minute_rid_num << " pause_start " << pause_time_start << " end " << pause_time_end);

    }else{
        CONSOLE_LOG("Scheduler: config loaded, daily_cap "<< max_daily_rid_num
            << " minute_cap " << max_minute_rid_num << " pause_start " << pause_time_start << " end " << pause_time_end);
    }
}
Example #7
0
/**
  * @brief  Initialize the target hardware and the console
  * @param  None
  * @retval None
  */
void MOD_PreInit(void)
{

  memset(MOD_table, 0, sizeof(GROUP_InitTypeDef));

  /* Init Console to save events log*/
  CONSOLE_Init();

  CONSOLE_LOG((uint8_t *)"[SYSTEM] Module Manager running....");

  /* Init Board specific hardware */
  BSP_Init();
  
  /*Init heap memory (located in SRAM)*/ 
  mem_pool_init();
}
Example #8
0
static int do_http_connect(struct update_context *ctx, const char *url) {
  LOG(LL_DEBUG, ("Connecting to: %s", url));

  struct mg_connect_opts opts;
  memset(&opts, 0, sizeof(opts));

#ifdef MG_ENABLE_SSL
  if (strlen(url) > 8 && strncmp(url, "https://", 8) == 0) {
    opts.ssl_server_name = get_cfg()->update.ssl_server_name;
    opts.ssl_ca_cert = get_cfg()->update.ssl_ca_file;
#ifndef cc3200
    if (opts.ssl_ca_cert == NULL) {
      /* Use global CA file if updater specific one is not set */
      opts.ssl_ca_cert = get_cfg()->tls.ca_file;
    }
#else
/*
 * SimpleLink only accepts one cert in DER format as a CA file so we can't
 * use a pre-packaged bundle and expect it to work, sadly.
 */
#endif
    opts.ssl_cert = get_cfg()->update.ssl_client_cert_file;
  }
#endif

  struct mg_connection *c = mg_connect_http_opt(&sj_mgr, fw_download_ev_handler,
                                                opts, url, NULL, NULL);

  if (c == NULL) {
    CONSOLE_LOG(LL_ERROR, ("Failed to connect to %s", url));
    return -1;
  }

  c->user_data = ctx;

  return 1;
}
Example #9
0
/**
* @brief  USBD_USR_DeviceDisonnected
*         Displays the message on LCD on device disconnection Event
* @param  None
* @retval Staus
*/
void USBD_USR_DeviceDisconnected (void)
{
    CONSOLE_LOG  ((uint8_t *)"[USBD] USB Device Disconnected..");
    USBD_SetStateMsg  ((uint8_t *)"STATE: USB Device Disconnected..");
}
Example #10
0
/**
* @brief  Displays the message on LCD on device suspend event
* @param  None
* @retval None
*/
void USBD_USR_DeviceSuspended(void)
{
    CONSOLE_LOG  ((uint8_t *)"[USBD] Device In suspend mode.");
    USBD_SetStateMsg  ((uint8_t *)"STATE: Device In Suspend mode.");
}
Example #11
0
/**
* @brief  Displays the message on LCD on device config event
* @param  None
* @retval Staus
*/
void USBD_USR_DeviceConfigured (void)
{
    CONSOLE_LOG  ((uint8_t *)"[USBD] Device Interface started.");
    USBD_SetStateMsg  ((uint8_t *)"STATE: Device running.");

}
Example #12
0
/**
* @brief  Displays the message on LCD on device lib initialization
* @param  None
* @retval None
*/
void USBD_USR_Init(void)
{
    CONSOLE_LOG  ((uint8_t *)"[USBD] USB device library started.");
}
	void StunServerListConfig::LoadFile(const TCHAR *file_name)
		//¶ÁÈ¡StunServerListÎļþ
	{
		tstring moduleName = file_name; 
		framework::mswin::Module module;
		framework::io::Path config_path;
		module.BuildLocalFilePath(config_path, moduleName.c_str());

		framework::io::StdFileReader config_reader;
		config_reader.OpenText(config_path);

		if (config_reader.IsOpen())
		{
			string config_line;
			stun_info_.clear();
			while(config_reader.ReadLine(config_line))
			{
				boost::algorithm::trim(config_line);
				if ( config_line.empty() == true || config_line[0] == '#' )
				{
					continue;
				}
				else
				{
					STUN_SERVER_INFO ds;
					bool is_succed = false;
					try
					{
						vector<string> tracker_s;
						char split_char_s[] = " \t\r\n";
						char ip_split_char_s[] = ".";
						boost::algorithm::split(tracker_s, config_line, boost::algorithm::is_any_of(split_char_s));

						int pos = 0;

						for(vector<string>::iterator iter = tracker_s.begin();
							iter != tracker_s.end(); iter ++)
						{
							if( boost::algorithm::trim_copy(*iter).empty() == true )
							{
								continue;
							}
							else if( pos == 0 )
							{
								if(boost::algorithm::to_lower_copy(*iter) == "udp")
								{
									ds.Type = 1;
								}
								else
								{
									//?
									ds.Type = 0;
								}
								pos ++;
							}
							else if( pos == 1 )
							{
								boost::asio::ip::address_v4 addr = boost::asio::ip::address_v4::from_string(*iter);
								ds.IP = addr.to_ulong();
								pos ++;
							}
							else if( pos == 2 )
							{
								ds.Port = boost::lexical_cast<u_short>(*iter);
								is_succed = true;
								break;
							}
						}	// end for
					}
					catch (boost::bad_lexical_cast&) 
					{
						assert(0);
					}
					if( is_succed == true )
					{
						stun_info_.push_back(ds);
					}
					else
					{
						CONSOLE_LOG("There\'s an error line in the stun server list file!");
					}
				}	// end if-else
			}	// end while
		}
		else
		{
			CONSOLE_LOG("StunServerListConfig::LoadFile() Failed to Open the stun server List File");
		}
	}
Example #14
0
static void fw_download_ev_handler(struct mg_connection *c, int ev, void *p) {
  struct mbuf *io = &c->recv_mbuf;
  struct update_context *ctx = (struct update_context *) c->user_data;
  (void) p;

  switch (ev) {
    case MG_EV_RECV: {
      if (ctx->archive_size == 0) {
        LOG(LL_DEBUG, ("Looking for HTTP header"));
        struct http_message hm;
        int parsed = mg_parse_http(io->buf, io->len, &hm, 0);
        if (parsed <= 0) {
          return;
        }
        if (hm.body.len != 0) {
          LOG(LL_DEBUG, ("HTTP header: file size: %d", (int) hm.body.len));
          if (hm.body.len == (size_t) ~0) {
            CONSOLE_LOG(LL_ERROR,
                        ("Invalid content-length, perhaps chunked-encoding"));
            ctx->status_msg =
                "Invalid content-length, perhaps chunked-encoding";
            c->flags |= MG_F_CLOSE_IMMEDIATELY;
            break;
          } else {
            ctx->archive_size = hm.body.len;
          }

          mbuf_remove(io, parsed);
        }
      }

      if (io->len != 0) {
        int res = updater_process(ctx, io->buf, io->len);
        LOG(LL_DEBUG, ("Processed %d bytes, result: %d", (int) io->len, res));

        mbuf_remove(io, io->len);

        if (res == 0) {
          /* Need more data, everything is OK */
          break;
        }

        if (res > 0) {
          if (!is_update_finished(ctx)) {
            /* Update terminated, but not because of error */
            notify_js(UJS_NOTHING_TODO, NULL);
            sj_clubby_send_status_resp(s_clubby_reply, 0, ctx->status_msg);
          } else {
            /* update ok */
            int len;
            char *upd_data = sj_clubby_repl_to_bytes(s_clubby_reply, &len);
            FILE *tmp_file = fopen(UPDATER_TEMP_FILE_NAME, "w");
            if (tmp_file == NULL || upd_data == NULL) {
              /* There is nothing we can do */
              free(upd_data);
              if (tmp_file) fclose(tmp_file);
              CONSOLE_LOG(LL_ERROR, ("Cannot save update status"));
            } else {
              fwrite(upd_data, 1, len, tmp_file);
              fclose(tmp_file);
              CONSOLE_LOG(LL_INFO, ("Update completed successfully"));
            }
            updater_finish(ctx);
          }
        } else if (res < 0) {
          /* Error */
          CONSOLE_LOG(LL_ERROR,
                      ("Update error: %d %s", ctx->result, ctx->status_msg));
          notify_js(UJS_ERROR, NULL);
          sj_clubby_send_status_resp(s_clubby_reply, 1, ctx->status_msg);
        }
        c->flags |= MG_F_CLOSE_IMMEDIATELY;
      }
      break;
    }
    case MG_EV_CLOSE: {
      if (ctx != NULL) {
        if (!is_update_finished(ctx)) {
          /* Connection was terminated by server */
          notify_js(UJS_ERROR, NULL);
          sj_clubby_send_status_resp(s_clubby_reply, 1, "Update failed");
        } else if (is_reboot_required(ctx) && !notify_js(UJS_COMPLETED, NULL)) {
          /*
           * Conection is closed by updater, rebooting if required
           * and allowed (by JS)
           */
          CONSOLE_LOG(LL_INFO, ("Rebooting device"));
          updater_schedule_reboot(100);
        }

        if (s_clubby_reply) {
          sj_clubby_free_reply(s_clubby_reply);
          s_clubby_reply = NULL;
        }
        updater_finish(ctx);
        updater_context_free(ctx);
        c->user_data = NULL;
      }

      break;
    }
  }
}
Example #15
0
static void handle_update_req(struct clubby_event *evt, void *user_data) {
  char *zip_url;
  struct json_token section = JSON_INVALID_TOKEN;
  struct json_token blob_url = JSON_INVALID_TOKEN;
  struct json_token args = evt->request.args;

  (void) user_data;
  LOG(LL_DEBUG, ("Update request received: %.*s", evt->request.args.len,
                 evt->request.args.ptr));

  const char *reply = "Malformed request";

  if (evt->request.args.type != JSON_TYPE_OBJECT) {
    goto bad_request;
  }

  json_scanf(args.ptr, args.len, "{section: %T, blob_url: %T}", &section,
             &blob_url);

  /*
   * TODO(alashkin): enable update for another files, not
   * firmware only
   */
  if (section.len == 0 || section.type != JSON_TYPE_STRING ||
      strncmp(section.ptr, "firmware", section.len) != 0 || blob_url.len == 0 ||
      blob_url.type != JSON_TYPE_STRING) {
    goto bad_request;
  }

  LOG(LL_DEBUG, ("zip url: %.*s", blob_url.len, blob_url.ptr));

  sj_clubby_free_reply(s_clubby_reply);
  s_clubby_reply = sj_clubby_create_reply(evt);

  /*
   * If user setup callback for updater, just call it.
   * User can start update with Sys.updater.start()
   */

  zip_url = calloc(1, blob_url.len + 1);
  if (zip_url == NULL) {
    CONSOLE_LOG(LL_ERROR, ("Out of memory"));
    return;
  }

  memcpy(zip_url, blob_url.ptr, blob_url.len);

  if (!notify_js(UJS_GOT_REQUEST, zip_url)) {
    struct update_context *ctx = updater_context_create();
    if (ctx == NULL) {
      reply = "Failed to init updater";
    } else if (start_update_download(ctx, zip_url) < 0) {
      reply = ctx->status_msg;
    }
  }

  free(zip_url);

  return;

bad_request:
  CONSOLE_LOG(LL_ERROR, ("Failed to start update: %s", reply));
  sj_clubby_send_status_resp(evt, 1, reply);
}
Example #16
0
/**
  * @brief  Background task
  * @param  pvParameters not used
  * @retval None
  */
static void Background_Task(void * pvParameters)
{
  static uint32_t ticks = 0;

  /* Init Modules manager */
  MOD_PreInit();

  /*Add modules here */
  MOD_AddModule(&mod_system, UTILITIES_GROUP);
  MOD_AddModule(&mod_audio, MULTIMEDIA_GROUP);
  MOD_AddModule(&mod_image, MULTIMEDIA_GROUP);
  MOD_AddModule(&mod_ethernet, CONNECTIVITY_GROUP);
  MOD_AddModule(&mod_camera, MULTIMEDIA_GROUP);
  MOD_AddModule(&mod_usbd, CONNECTIVITY_GROUP);
  MOD_AddModule(&mod_recorder, MULTIMEDIA_GROUP);
  MOD_AddModule(&mod_serial, CONNECTIVITY_GROUP);
  MOD_AddModule(&mod_calendar, UTILITIES_GROUP);
  MOD_AddModule(&mod_filemgr, UTILITIES_GROUP);
  MOD_AddModule(&mod_console, UTILITIES_GROUP);
  MOD_AddModule(&mod_credits, UTILITIES_GROUP);  

  CONSOLE_LOG((uint8_t *)"[SYSTEM] System modules added.");

  /* Show startup Page */
  GL_Startup();

  /* Init Libraries and stack here */
  MOD_LibInit();

  /* Show the main menu and start*/
  GL_Init();

  while (1)
  {
    if ( ticks++ > 10 )
    {
      ticks = 0;

      /* toggle LED1..4 each 100ms */
      STM_EVAL_LEDToggle(LED1);
      STM_EVAL_LEDToggle(LED2);
      STM_EVAL_LEDToggle(LED3);
      STM_EVAL_LEDToggle(LED4);

      /* Wait for HMI events */
      GL_Handle_Inputs();

      /*Update GUI processes */
      GL_Background_Handler();

      /* power saving mode */
      GL_LowPower();

      /* Apply new settings if they were changed */
      GL_HandleSystemSettingsChange();

      /* Display processes running in background */
      GL_UpdateBackgroundProcessStatus();
    }

    /* Handle modules background tasks */
    MOD_HandleModulesBackground();

    /* This task is handled periodically, each 10 mS */
    vTaskDelay(10);
  }
}