Example #1
0
void HCI_Event_CB(void *pckt)
{
  hci_uart_pckt *hci_pckt = pckt;
  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:
    //evt_disconn_complete *evt = (void *)event_pckt->data;
    GAP_DisconnectionComplete_CB();
    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;
      GAP_ConnectionComplete_CB(cc->peer_bdaddr,cc->handle);
      break;
    }
    }
    break;
  }

  case EVT_VENDOR:
  {
    evt_blue_aci *blue_evt = (void*)event_pckt->data;
    switch(blue_evt->ecode)
    {
    case EVT_BLUE_GATT_READ_PERMIT_REQ:
    {
      evt_gatt_read_permit_req *pr = (void*)blue_evt->data;
      Read_Request_CB(pr->attr_handle);
      break;
#ifdef ST_OTA_BTL
    case EVT_BLUE_GATT_ATTRIBUTE_MODIFIED:
      evt_gatt_attr_modified *am = (void*)blue_evt->data;
      //PRINTF("-> modified attribute 0x%04X \r\n",am->attr_handle);
      OTA_Write_Request_CB(am);
      break;
#endif
    }
    }
    break;
  }
  }
}
Example #2
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;
    }
}
Example #3
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:
    {
        notification_enabled = 0;
        ble_device_on_disconnect(event_pckt->data[3]);
    }
    break;

    case EVT_LE_META_EVENT:
    {
        evt_le_meta_event *evt = (void *)event_pckt->data;

        switch(evt->subevent) {
        case EVT_LE_CONN_COMPLETE:
        {
            ble_device_on_connect();
            evt_le_connection_complete *cc = (void *)evt->data;
            connection_information(cc->handle);

        }
        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;
            }
        }
        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;

        }
    }
    break;
    }
}