Esempio n. 1
0
/* This is the main event handler for this project. The application framework
 * calls this function in response to the various events in the system.
 */
int common_event_handler(int event, void *data)
{
    int ret;
    static bool is_cloud_started;
    switch (event) {
    case AF_EVT_WLAN_INIT_DONE:
        ret = psm_cli_init();
        if (ret != WM_SUCCESS)
            wmprintf("Error: psm_cli_init failed\r\n");
        int i = (int) data;

        if (i == APP_NETWORK_NOT_PROVISIONED) {
            wmprintf("\r\nPlease provision the device "
                     "and then reboot it:\r\n\r\n");
            wmprintf("psm-set network ssid <ssid>\r\n");
            wmprintf("psm-set network security <security_type>"
                     "\r\n");
            wmprintf("    where: security_type: 0 if open,"
                     " 3 if wpa, 4 if wpa2\r\n");
            wmprintf("psm-set network passphrase <passphrase>"
                     " [valid only for WPA and WPA2 security]\r\n");
            wmprintf("psm-set network configured 1\r\n");
            wmprintf("pm-reboot\r\n\r\n");
        } else
            app_sta_start();

        break;
    case AF_EVT_NORMAL_CONNECTED:
        set_device_time();
        if (!is_cloud_started) {
            configure_gpios();
            os_thread_sleep(2000);
            ret = os_thread_create(
                      /* thread handle */
                      &app_thread,
                      /* thread name */
                      "evrythng_demo_thread",
                      /* entry function */
                      evrythng_task,
                      /* argument */
                      0,
                      /* stack */
                      &app_stack,
                      /* priority - medium low */
                      OS_PRIO_3);
            is_cloud_started = true;
        }
        break;
    default:
        break;
    }

    return 0;
}
Esempio n. 2
0
static void modules_init()
{
    int ret;
    struct partition_entry *p;
    flash_desc_t fl;

    /*
     * Initialize wmstdio prints
     */
    ret = wmstdio_init(UART0_ID, 115200);
    if (ret != WM_SUCCESS) {
        appln_critical_error_handler((void *) -WM_FAIL);
    }

    /* Initialize time subsystem.
     *
     * Initializes time to 1/1/1970 epoch 0.
     */
    ret = wmtime_init();
    if (ret != WM_SUCCESS) {
        wmprintf("Error: wmtime_init failed");
        appln_critical_error_handler((void *) -WM_FAIL);
    }

    /*
     * Initialize CLI Commands
     */
    ret = cli_init();
    if (ret != WM_SUCCESS) {
        LOG_ERROR("Error: cli_init failed");
        appln_critical_error_handler((void *) -WM_FAIL);
    }

    /* Initialize the partition module */
    ret = part_init();
    if (ret != 0) {
        LOG_ERROR("Failed to initialize partition\r\n");
        appln_critical_error_handler((void *) -WM_FAIL);
    }
    p = part_get_layout_by_id(FC_COMP_PSM, NULL);
    if (!p) {
        LOG_ERROR("Error: no psm partition found");
        appln_critical_error_handler((void *) -WM_FAIL);
    }
    part_to_flash_desc(p, &fl);

#if defined CONFIG_CPU_MC200 && defined CONFIG_WiFi_8801
    //check psm _format
    psm_format_check(&fl);
#endif
    /* Initilize psm module */
    ret = app_psm_init();
    if (ret != 0) {
        LOG_ERROR("Failed to initialize psm module\r\n");
        appln_critical_error_handler((void *) -WM_FAIL);
    }

    wmprintf("\n\r");
    wmprintf("_|      _|  _|_|_|  _|_|_|    _|_|  \n\r");
    wmprintf("_|_|  _|_|    _|      _|    _|    _|\n\r");
    wmprintf("_|  _|  _|    _|      _|    _|    _|\n\r");
    wmprintf("_|      _|    _|      _|    _|    _|\n\r");
    wmprintf("_|      _|  _|_|_|  _|_|_|    _|_|  \n\r");
    print_versions();

    read_provision_status();

#ifndef RELEASE
    /* Initilize cli for psm module */
    ret = psm_cli_init();
    if (ret != 0) {
        LOG_ERROR("Failed to register psm-cli commands\r\n");
        appln_critical_error_handler((void *) -WM_FAIL);
    }
#endif

    ret = gpio_drv_init();
    if (ret != WM_SUCCESS) {
        LOG_ERROR("Error: gpio_drv_init failed");
        appln_critical_error_handler((void *) -WM_FAIL);
    }

    ret = aes_drv_init();
    if (ret != WM_SUCCESS) {
        LOG_ERROR("Error: aes drv init failed");
        appln_critical_error_handler((void *) -WM_FAIL);
    }

    ret = factory_cli_init();
    if (ret != 0) {
        LOG_ERROR("Error: factory_cli_init failed");
        appln_critical_error_handler((void *) -WM_FAIL);
    }

    ret = miio_chip_rpc_init();
    if (ret != 0) {
        LOG_ERROR("Error: miio_chip_rpc_cli_init failed");
        appln_critical_error_handler((void *) -WM_FAIL);
    }

#ifndef RELEASE
    ret = appln_cli_init();
    if (ret != 0) {
        LOG_ERROR("Error: appln init failed");
        appln_critical_error_handler((void *) -WM_FAIL);
    }
#endif

    /* init add on interface */
    init_addon_interface();

    ret = ota_init();
    if (ret != 0) {
        LOG_ERROR("Error: ota init failed");
        appln_critical_error_handler((void *) -WM_FAIL);
    }

#ifdef MIIO_COMMANDS
    ret = mcmd_create(UART1_ID);
    if (ret < 0) {
        LOG_ERROR("Error: miio command init failed(%d)\r\n", ret);
        appln_critical_error_handler((void *) -WM_FAIL);
    }
#endif

    /*
	* Initialize Power Management Subsystem
	*/
	ret = pm_init();
	if (ret != WM_SUCCESS) {
		LOG_ERROR("Error: pm_init failed");
		appln_critical_error_handler((void *) -WM_FAIL);
	}

}