Ejemplo n.º 1
0
void ble_device_on_message(uint8_t type, uint16_t length, uint8_t* value)
{
    mesh_manuf_data_t rx_data ;
    rx_data.data = (((uint16_t)value[0] << 8) | value[1]);
    printf("value: %x\n", rx_data.data);
    run_when_idle(mesh_rx_host_message, &rx_data);
}
Ejemplo n.º 2
0
void mesh_rx_scan_data(void* data)
{
      mesh_manuf_data_t* rx_data = data;
  
    if(rx_data->adv_info_number > adv_info_number){
      
       if((rx_data->group_id == 0x0000)  || (((rx_data->id & MESH_ID) || (rx_data->id == 0x0000)) && (rx_data->group_id & MESH_GROUP_ID))){
          if(rx_data->data & LED_ON){
             BSP_LED_On(LED0);
          }
          if(rx_data->data & LED_OFF){
             BSP_LED_Off(LED0);
          }
       }
       run_when_idle(mesh_manuf_data_config, data);
       run_when_idle(mesh_adv_data_update, NULL);
    }
}
Ejemplo n.º 3
0
void mesh_rx_host_message(void* data)
{
    mesh_manuf_data_t* rx_data = data;
 
     if((rx_data->group_id == 0x0000)  || (((rx_data->id & MESH_ID) || (rx_data->id == 0x0000)) && (rx_data->group_id & MESH_GROUP_ID))){
      if(rx_data->data & LED_ON){
         BSP_LED_On(LED0);
      }
      if(rx_data->data & LED_OFF){
         BSP_LED_Off(LED0);
      }
   }
    
    run_when_idle(mesh_manuf_data_config, data);
}
Ejemplo n.º 4
0
void mesh_disconnect_handle(void* data)
{
    tBleStatus ret;
 
    ret = ble_host_stop_scan();
    if(ret){
       printf("ble_host_stop_scan failed \n");
    }
    
    ret = ble_device_start_advertising();
    if(ret){
       printf("ble_device_start_advertising \n");
    }
    
    run_when_idle(mesh_adv_data_update, NULL);
}
Ejemplo n.º 5
0
/**
 * @brief  Callback processing the ACI events.
 * @note   Inside this function each event must be identified and correctly
 *         parsed.
 * @param  void* Pointer to the ACI packet
 * @retval None
 */
void HCI_Event_CB(void *pckt)
{
    hci_uart_pckt *hci_pckt = pckt;
    /* obtain event packet */
    hci_event_pckt *event_pckt = (hci_event_pckt*)hci_pckt->data;
    if(hci_pckt->type != HCI_EVENT_PKT)
        return;

    switch(event_pckt->evt) {

    case EVT_DISCONN_COMPLETE:
    {
     disconn_event_pckt *evt = (void *)event_pckt->data;
     printf("conn handle: %x\n", evt->conn_handle);
#if defined (CLIENT_ROLE) || defined (CLIENT_SERVER_ROLE)
        host_notification_enabled = 0;
#endif
        /*Host*/
       GAP_DisconnectionComplete_CB();
       /*device*/
       notification_enabled = 0;
       ble_device_on_disconnect(evt->disconn_reason);
     
    }
    break;
    
    case EVT_LE_META_EVENT:
    {
        evt_le_meta_event *evt = (void *)event_pckt->data;
        switch(evt->subevent) {
        case EVT_LE_CONN_COMPLETE:
        {
            evt_le_connection_complete *cc = (void *)evt->data;
            if(cc->role == SLAVE_ROLE){
                /*device*/
                ble_device_on_connect();
                connection_information(cc->handle);
            }
            if(cc->role == MASTER_ROLE){
                /*host*/
                GAP_ConnectionComplete_CB(cc->peer_bdaddr, cc->handle);
            }
        }
        break;
        case EVT_LE_ADVERTISING_REPORT:
        {
#if defined (CLIENT_ROLE) || defined (CLIENT_SERVER_ROLE)
            le_advertising_info* adv_data = (void *)((event_pckt->data)+2);
            run_after_delay(ble_host_device_found, adv_data, 2);
#endif
        }
        break;
        }
    }
    break;

    case EVT_VENDOR:
    {
        evt_blue_aci *blue_evt = (void*)event_pckt->data;
        switch(blue_evt->ecode) {
        case EVT_BLUE_GATT_ATTRIBUTE_MODIFIED:
        {
            /* this callback is invoked when a GATT attribute is modified
            extract callback data and pass to suitable handler function */
            evt_gatt_attr_modified *evt = (evt_gatt_attr_modified*)blue_evt->data;
            ///on message
            if(evt->att_data[1] > 0) {
                ble_device_on_message(evt->att_data[0], evt->att_data[1], (evt->att_data)+2);
            } else if(evt->att_data[0] == 1) {
                notification_enabled = 1;
#if defined (CLIENT_ROLE) || defined (CLIENT_SERVER_ROLE)
                host_notification_enabled = 1;
#endif
            }
        }
        break;
        case EVT_BLUE_GATT_NOTIFICATION:
        {
            evt_gatt_attr_notification *evt = (evt_gatt_attr_notification*)blue_evt->data;
            GATT_Notification_CB(evt->attr_handle, evt->event_data_length - 2, evt->attr_value);
        }
        break;
        case EVT_BLUE_GATT_READ_PERMIT_REQ:
        {
            evt_gatt_read_permit_req *pr = (void*)blue_evt->data;
            Read_Request_CB(pr->attr_handle);
        }
        break;
        case EVT_BLUE_GAP_DEVICE_FOUND:
        {
            printf("scanned one device\n\r");
        }
        break;
        case EVT_BLUE_GAP_PROCEDURE_COMPLETE:
        {
#ifdef CLIENT_SERVER_ROLE
            run_after_delay(ble_host_start_scan, NULL, 10);
            printf("EVT_BLUE_GAP_PROCEDURE_COMPLETE \n\r");
#endif
        }
        break;
        case EVT_BLUE_GATT_DISC_READ_CHAR_BY_UUID_RESP:
#if defined (CLIENT_ROLE) || defined (CLIENT_SERVER_ROLE)
            if(BLE_Role & CLIENT) {
                printf("EVT_BLUE_GATT_DISC_READ_CHAR_BY_UUID_RESP\n");

                evt_gatt_disc_read_char_by_uuid_resp *resp = (void*)blue_evt->data;

                if (start_read_write_char_handle && !end_read_write_char_handle)
                {
                    write_handle = resp->attr_handle;
                    printf("write_handle  %04X\n", write_handle);
                }
                else if (start_read_notify_read_char_handle && !end_read_notify_read_char_handle)
                {
                    notify_read_handle = resp->attr_handle;
                    printf("notify_read_handle  %04X\n", notify_read_handle);
                }
                else if (start_read_write_without_rsp_char_handle && !end_read_write_without_rsp_char_handle)
                {
                    write_without_rsp_handle = resp->attr_handle;
                    printf("write_without_rsp_handle  %04X\n", write_without_rsp_handle);
                }
                else if (start_read_notify_char_handle && !end_read_notify_char_handle)
                {
                    notify_handle = resp->attr_handle;
                    printf("notify_handle %04X\n", notify_handle);
                }
            }
#endif
            break;

        case EVT_BLUE_GATT_PROCEDURE_COMPLETE:
#if defined (CLIENT_ROLE) || defined (CLIENT_SERVER_ROLE)
            if(BLE_Role & CLIENT) {
                /* Wait for gatt procedure complete event trigger related to Discovery Charac by UUID */
                //evt_gatt_procedure_complete *pr = (void*)blue_evt->data;

                if (start_read_write_char_handle && !end_read_write_char_handle)
                {
                    end_read_write_char_handle = TRUE;
                    run_when_idle(ble_host_discover_char, NULL);

                }
                else if (start_read_notify_read_char_handle && !end_read_notify_read_char_handle)
                {
                    end_read_notify_read_char_handle = TRUE;
                    run_when_idle(ble_host_discover_char, NULL);
                }
                else if (start_read_write_without_rsp_char_handle && !end_read_write_without_rsp_char_handle)
                {
                    end_read_write_without_rsp_char_handle = TRUE;
                    run_when_idle(ble_host_discover_char, NULL);
                }
                else if (start_read_notify_char_handle && !end_read_notify_char_handle)
                {
                    end_read_notify_char_handle = TRUE;
                    run_when_idle(ble_host_discover_char, NULL);
                }
            }
#endif
            break;
        }
    }
    break;
    }
}
Ejemplo n.º 6
0
void imu_sensor_magneto_irq_callback(void)
{
    run_when_idle(imu_sensor_magneto_data_handle,NULL);

}
Ejemplo n.º 7
0
void imu_sensor_dma_read_call_back(void)
{

    run_when_idle(imu_sensor_6axis_data_handle, NULL);
}