Esempio n. 1
0
wiced_result_t wiced_bt_rfcomm_deinit_socket( wiced_bt_rfcomm_socket_t* socket )
{
    if ( socket->id != RFCOMM_SOCKET_ID )
    {
        return WICED_BT_SUCCESS;
    }

//        if ( FEATURE_MASK == MPAF_RFCOMM_SERVICE_CHANNEL_NUMBER_MASK )
//        {
//            uint8_t status;
//
//            socket->shared.lock( socket );
//            status = socket->shared.status;
//            socket->shared.unlock( socket );
//
//            if ( ( status & RFCOMM_SOCKET_TERMINATED ) != 0 )
//            {
//                if ( rfcomm_delete_sdp_record( socket ) != WICED_BT_SUCCESS )
//                {
//                    return WICED_ERROR;
//                }
//            }
//        }

    wiced_rtos_deinit_semaphore( &socket->semaphore );
    wiced_rtos_deinit_mutex( &socket->shared.mutex );
    bt_linked_list_deinit( &socket->shared.rx_packet_list );
    memset( socket, 0, sizeof( *socket ) );
    return WICED_BT_SUCCESS;
}
Esempio n. 2
0
void platform_semaphore_deinit(Semaphore* s)
{
    if (!s)
    {
        platform_printf("%s: invalid semaphore %p\n", __func__, s);
        return;
    }

    wiced_rtos_deinit_semaphore(&s->sem);
}
Esempio n. 3
0
wiced_result_t sniff_security(SnifferInfo* info) {

    wiced_result_t result = wiced_rtos_init_semaphore(&info->complete);
    if (result!=WICED_SUCCESS) return result;
    result = wiced_wifi_scan_networks(sniffer, info);
    if (result==WICED_SUCCESS) {
        wiced_rtos_get_semaphore(&info->complete, 30000);
    }
    wiced_rtos_deinit_semaphore(&info->complete);
    if (!info->rssi)
        result = WICED_NOT_FOUND;
    return result;
}
Esempio n. 4
0
void system_monitor_thread_main( wiced_thread_arg_t arg )
{
    UNUSED_PARAMETER(arg);

    memset(system_monitors, 0, sizeof(system_monitors));

    if (wiced_rtos_init_semaphore(&system_monitor_thread_semaphore) != WICED_SUCCESS)
    {
        wiced_assert("semaphore init failed", 0);
    }

    /* - Can watch threads
     * Each thread can set a counter that is decremented every event.
     * Once any timer == 0, the watchdog is no longer kicked
     *
     * - Can watch packet buffer status
     * If no RX packets are available, take timestamp (T). If (current time - T) > X seconds, stop kicking watchdog.
     * X can be 10 second default. Time will be set to zero once RX buffer is freed
     *
     * - Can watch bus data credits
     * If no credits are available, take timestamp (B). If (current time - B) > X seconds, stop kicking watchdog.
     * This will be dependent on if WLAN is up. Timer will be set to 0 if credits become available.
     */
    while (1)
    {
        int a;
        uint32_t current_time = host_rtos_get_time();

        for (a = 0; a < MAXIMUM_NUMBER_OF_SYSTEM_MONITORS; ++a)
        {
            if (system_monitors[a] != NULL)
            {
                if ((current_time - system_monitors[a]->last_update) > system_monitors[a]->longest_permitted_delay)
                {
                    /* A system monitor update period has been missed and hence explicitly resetting the MCU rather than waiting for the watchdog to bite */
                    wiced_framework_reboot();
                }
            }
        }
        wiced_watchdog_kick();
        wiced_rtos_get_semaphore(&system_monitor_thread_semaphore, DEFAULT_SYSTEM_MONITOR_PERIOD);
    }
    /* Should never get here */
    wiced_rtos_deinit_semaphore(&system_monitor_thread_semaphore);

    WICED_END_OF_CURRENT_THREAD( );
}
Esempio n. 5
0
wiced_result_t command_console_deinit(void)
{
    wiced_result_t result;
    cons.quit = WICED_TRUE;

    /* Wait on a semaphore till the console thread is ready to quit */
    result = wiced_rtos_get_semaphore(&cons.console_quit_semaphore, 1000);
    if( result != WICED_SUCCESS )
    {
        return result;
    }
    wiced_rtos_thread_join(&cons.console_thread);
    result = wiced_rtos_delete_thread( &cons.console_thread);
    wiced_rtos_deinit_semaphore(&cons.console_quit_semaphore);
    if( cons.uart != STDIO_UART )
    {
        wiced_uart_deinit(cons.uart);
    }
    return WICED_SUCCESS;
}
/*
 * Main application
 */
void application_start( void )
{
    char            *msg = MSG_OFF;
    wiced_result_t   ret = WICED_SUCCESS;
    int              retries;
    uint16_t         light_value;

    ret = aws_app_init(&app_info);

    /* Initialise Light sensor */
    WPRINT_APP_INFO( ("Initializing Light Sensor\n" ));
    wiced_adc_init( WICED_LIGHT, 5 );

    do
    {
        ret = aws_mqtt_conn_open( app_info.mqtt_object, mqtt_connection_event_cb );
        if ( ret != WICED_SUCCESS )
        {
            WPRINT_APP_INFO(("Failed\n"));
            break;
        }

        while ( 1 )
        {
            /* Read light sensor */
            wiced_adc_take_sample( WICED_LIGHT, &light_value );
            WPRINT_APP_INFO( ("Light value %u\n", light_value) );

            if ( light_value >= LIGHT_THRESHOLD )
            {
                msg = MSG_ON;
            }
            else
            {
                msg = MSG_OFF;
            }

            /* Controlling the LED by publishing to mqtt topic "WICED_BULB" */
            retries = 0;
            do
            {
                ret = aws_mqtt_app_publish( app_info.mqtt_object, WICED_MQTT_QOS_DELIVER_AT_LEAST_ONCE, (uint8_t*) app_info.thing_name, (uint8_t*) msg, strlen( msg ) );
                retries++ ;
            } while ( ( ret != WICED_SUCCESS ) && ( retries < MQTT_PUBLISH_RETRY_COUNT ) );
            if ( ret != WICED_SUCCESS )
            {
                break;
            }

            wiced_rtos_delay_milliseconds( 5000 );
        }

        aws_mqtt_conn_close( app_info.mqtt_object );

        wiced_rtos_delay_milliseconds( MQTT_DELAY_IN_MILLISECONDS * 2 );
    } while ( 1 );

    aws_mqtt_conn_close( app_info.mqtt_object );

    wiced_rtos_deinit_semaphore( &app_info.msg_semaphore );
    WPRINT_APP_INFO(("[MQTT] Deinit connection...\n"));
    ret = wiced_mqtt_deinit( app_info.mqtt_object );
    free( app_info.mqtt_object );
    app_info.mqtt_object = NULL;

    return;
}
/******************************************************
 *               Function Definitions
 ******************************************************/
void application_start( void )
{
    wiced_result_t ret = WICED_SUCCESS;
    uint32_t       connection_retries = 0;
    uint32_t       retries = 0;

    ret = aws_app_init( &app_info );

    wiced_gpio_input_irq_enable( WICED_BUTTON1, IRQ_TRIGGER_RISING_EDGE, publish_callback, NULL );
    do
    {
        ret = aws_mqtt_conn_open( app_info.mqtt_object, mqtt_connection_event_cb );
        connection_retries++ ;
    } while ( ( ret != WICED_SUCCESS ) && ( connection_retries < WICED_MQTT_CONNECTION_NUMBER_OF_RETRIES ) );

    aws_mqtt_app_publish( app_info.mqtt_object, WICED_MQTT_QOS_DELIVER_AT_LEAST_ONCE, (uint8_t*) app_info.shadow_state_topic, (uint8_t*) SHADOW_PUBLISH_MESSAGE_STR_OFF_DESIRED_AND_REPORTED, sizeof( SHADOW_PUBLISH_MESSAGE_STR_OFF_DESIRED_AND_REPORTED ) );

    wiced_rtos_delay_milliseconds( MQTT_DELAY_IN_MILLISECONDS * 2 );

    aws_mqtt_app_subscribe( app_info.mqtt_object, app_info.shadow_delta_topic, WICED_MQTT_QOS_DELIVER_AT_LEAST_ONCE );

    do
    {
        ret = aws_mqtt_app_subscribe( app_info.mqtt_object, app_info.thing_name, WICED_MQTT_QOS_DELIVER_AT_MOST_ONCE );
        retries++ ;
    } while ( ( ret != WICED_SUCCESS ) && ( retries < WICED_MQTT_SUBSCRIBE_RETRY_COUNT ) );
    if ( ret != WICED_SUCCESS )
    {
        return;
    }

    while ( 1 )
    {
        /* Wait forever on wake semaphore until the LED status is changed */
        wiced_rtos_get_semaphore( &app_info.wake_semaphore, WICED_NEVER_TIMEOUT );

        /* Toggle the LED */
        if ( ( strncasecmp( led_status, "OFF", 3 ) == 0 ) && smart_control == 1 )
        {
            wiced_gpio_output_low( WICED_LED1 );
            led_status = "OFF";
            WPRINT_APP_INFO(("[MQTT] Publishing to Thing state topic\n"));
            aws_mqtt_app_publish( app_info.mqtt_object, WICED_MQTT_QOS_DELIVER_AT_LEAST_ONCE, (uint8_t*) app_info.shadow_state_topic, (uint8_t*) SHADOW_PUBLISH_MESSAGE_STR_OFF_DESIRED_AND_REPORTED_STATUS_ON, sizeof( SHADOW_PUBLISH_MESSAGE_STR_OFF_DESIRED_AND_REPORTED_STATUS_ON ) );
        }
        else if ( ( strncasecmp( led_status, "ON", 2 ) == 0 ) && smart_control == 0 )
        {
            wiced_gpio_output_high( WICED_LED1 );
            led_status = "ON";
            WPRINT_APP_INFO(("[MQTT] Publishing to Thing state topic\n"));
            aws_mqtt_app_publish( app_info.mqtt_object, WICED_MQTT_QOS_DELIVER_AT_LEAST_ONCE, (uint8_t*) app_info.shadow_state_topic, (uint8_t*) SHADOW_PUBLISH_MESSAGE_STR_ON_DESIRED_AND_REPORTED_STATUS_OFF, sizeof( SHADOW_PUBLISH_MESSAGE_STR_ON_DESIRED_AND_REPORTED_STATUS_OFF ) );
        }
        else if ( ( strncasecmp( led_status, "ON", 2 ) == 0 ) && smart_control == 1 )
        {
            wiced_gpio_output_high( WICED_LED1 );
            led_status = "ON";
            WPRINT_APP_INFO(("[MQTT] Publishing to Thing state topic\n"));
            aws_mqtt_app_publish( app_info.mqtt_object, WICED_MQTT_QOS_DELIVER_AT_LEAST_ONCE, (uint8_t*) app_info.shadow_state_topic, (uint8_t*) SHADOW_PUBLISH_MESSAGE_STR_ON_DESIRED_AND_REPORTED, sizeof( SHADOW_PUBLISH_MESSAGE_STR_ON_DESIRED_AND_REPORTED ) );
        }
        else
        {
            wiced_gpio_output_low( WICED_LED1 );
            led_status = "OFF";
            WPRINT_APP_INFO(("[MQTT] Publishing to Thing state topic\n"));
            aws_mqtt_app_publish( app_info.mqtt_object, WICED_MQTT_QOS_DELIVER_AT_LEAST_ONCE, (uint8_t*) app_info.shadow_state_topic, (uint8_t*) SHADOW_PUBLISH_MESSAGE_STR_OFF_DESIRED_AND_REPORTED, sizeof( SHADOW_PUBLISH_MESSAGE_STR_OFF_DESIRED_AND_REPORTED ) );
        }
    }

    aws_mqtt_conn_close( app_info.mqtt_object );

    wiced_rtos_deinit_semaphore( &app_info.msg_semaphore );
    ret = wiced_mqtt_deinit( app_info.mqtt_object );
    wiced_rtos_deinit_semaphore( &app_info.wake_semaphore );
    free( app_info.mqtt_object );
    app_info.mqtt_object = NULL;

    return;
}