void handle_gatt_client_event(le_event_t * event){ le_service_t service; le_characteristic_t characteristic; switch(state){ case TC_W4_SERVICE_RESULT: switch(event->type){ case GATT_SERVICE_QUERY_RESULT: service = ((le_service_event_t *) event)->service; dump_service(&service); services[service_count++] = service; break; case GATT_QUERY_COMPLETE: state = TC_W4_CHARACTERISTIC_RESULT; service_index = 0; printf("\ntest client - CHARACTERISTIC for SERVICE "); printUUID128(service.uuid128); printf("\n"); gatt_client_discover_characteristics_for_service(gc_handle, &services[service_index]); break; default: break; } break; case TC_W4_CHARACTERISTIC_RESULT: switch(event->type){ case GATT_CHARACTERISTIC_QUERY_RESULT: characteristic = ((le_characteristic_event_t *) event)->characteristic; dump_characteristic(&characteristic); break; case GATT_QUERY_COMPLETE: if (service_index < service_count) { state = TC_W4_CHARACTERISTIC_RESULT; service = services[service_index++]; printf("\ntest client - CHARACTERISTIC for SERVICE "); printUUID128(service.uuid128); printf(", [0x%04x-0x%04x]\n", service.start_group_handle, service.end_group_handle); gatt_client_discover_characteristics_for_service(gc_handle, &service); break; } state = TC_W4_DISCONNECT; service_index = 0; gap_disconnect(gc_handle); break; default: break; } break; default: break; } }
static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ UNUSED(packet_type); UNUSED(channel); UNUSED(size); gatt_client_service_t service; gatt_client_characteristic_t characteristic; switch(hci_event_packet_get_type(packet)){ case GATT_EVENT_SERVICE_QUERY_RESULT:\ gatt_event_service_query_result_get_service(packet, &service); dump_service(&service); services[service_count++] = service; break; case GATT_EVENT_CHARACTERISTIC_QUERY_RESULT: gatt_event_characteristic_query_result_get_characteristic(packet, &characteristic); dump_characteristic(&characteristic); break; case GATT_EVENT_QUERY_COMPLETE: if (search_services){ // GATT_EVENT_QUERY_COMPLETE of search services service_index = 0; printf("\nGATT browser - CHARACTERISTIC for SERVICE %s\n", uuid128_to_str(service.uuid128)); search_services = 0; gatt_client_discover_characteristics_for_service(handle_gatt_client_event, connection_handler, &services[service_index]); } else { // GATT_EVENT_QUERY_COMPLETE of search characteristics if (service_index < service_count) { service = services[service_index++]; printf("\nGATT browser - CHARACTERISTIC for SERVICE %s, [0x%04x-0x%04x]\n", uuid128_to_str(service.uuid128), service.start_group_handle, service.end_group_handle); gatt_client_discover_characteristics_for_service(handle_gatt_client_event, connection_handler, &service); break; } service_index = 0; gap_disconnect(connection_handler); } break; default: break; } }
void handle_gatt_client_event(le_event_t * event){ switch(tc_state){ case TC_W4_SERVICE_RESULT: switch(event->type){ case GATT_SERVICE_QUERY_RESULT: service = ((le_service_event_t *) event)->service; dump_service(&service); break; case GATT_QUERY_COMPLETE: tc_state = TC_W4_CHARACTERISTIC_RESULT; printf("\n test client - ENABLE CHARACTERISTIC for SERVICE QUERY 1: \n"); dump_service(&service); gatt_client_discover_characteristics_for_service_by_uuid128(&test_gatt_client_context, &service, acc_chr_enable_uuid); break; default: break; } break; case TC_W4_CHARACTERISTIC_RESULT: switch(event->type){ case GATT_CHARACTERISTIC_QUERY_RESULT: enable_characteristic = ((le_characteristic_event_t *) event)->characteristic; dump_characteristic(&enable_characteristic); break; case GATT_QUERY_COMPLETE: tc_state = TC_W4_ACC_ENABLE; printf("\n test client - ACC ENABLE\n"); gatt_client_write_value_of_characteristic(&test_gatt_client_context, enable_characteristic.value_handle, 1, acc_enable); break; default: break; } break; case TC_W4_ACC_ENABLE: tc_state = TC_W4_ACC_CLIENT_CONFIG_CHARACTERISTIC_RESULT; printf("\n test client - CLIENT CONFIG CHARACTERISTIC for SERVICE QUERY with UUID"); printUUID128(service.uuid128); printf("\n"); gatt_client_discover_characteristics_for_service_by_uuid128(&test_gatt_client_context, &service, acc_chr_client_config_uuid); break; case TC_W4_ACC_CLIENT_CONFIG_CHARACTERISTIC_RESULT: switch(event->type){ case GATT_CHARACTERISTIC_QUERY_RESULT: config_characteristic = ((le_characteristic_event_t *) event)->characteristic; dump_characteristic(&config_characteristic); break; case GATT_QUERY_COMPLETE: tc_state = TC_W4_ACC_DATA; printf("\n test client - ACC Client Configuration\n"); gatt_client_write_client_characteristic_configuration(&test_gatt_client_context, &config_characteristic, GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION); break; default: break; } break; case TC_W4_ACC_DATA: printf("ACC Client Data: "); if ( event->type != GATT_NOTIFICATION && event->type != GATT_INDICATION ) break; dump_characteristic_value((le_characteristic_value_event_t *) event); break; default: printf("Client, unhandled state %d\n", tc_state); break; } }
static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ int status; uint8_t battery_level; switch(state){ case TC_W4_SERVICE_RESULT: switch(hci_event_packet_get_type(packet)){ case GATT_EVENT_SERVICE_QUERY_RESULT: gatt_event_service_query_result_get_service(packet, &battery_service); dump_service(&battery_service); break; case GATT_EVENT_QUERY_COMPLETE: if (packet[4] != 0){ printf("SERVICE_QUERY_RESULT - Error status %x.\n", packet[4]); add_to_blacklist(report.address); gap_disconnect(connection_handle); break; } state = TC_W4_CHARACTERISTIC_RESULT; printf("\nSearch for battery level characteristic.\n"); gatt_client_discover_characteristics_for_service_by_uuid16(handle_gatt_client_event, connection_handle, &battery_service, battery_level_characteristic_uuid); break; default: break; } break; case TC_W4_CHARACTERISTIC_RESULT: switch(hci_event_packet_get_type(packet)){ case GATT_EVENT_CHARACTERISTIC_QUERY_RESULT: gatt_event_characteristic_query_result_get_characteristic(packet, &config_characteristic); dump_characteristic(&config_characteristic); break; case GATT_EVENT_QUERY_COMPLETE: if (packet[4] != 0){ printf("CHARACTERISTIC_QUERY_RESULT - Error status %x.\n", packet[4]); add_to_blacklist(report.address); gap_disconnect(connection_handle); break; } state = TC_W4_BATTERY_DATA; printf("\nConfigure battery level characteristic for notify.\n"); status = gatt_client_write_client_characteristic_configuration(handle_gatt_client_event, connection_handle, &config_characteristic, GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION); if (status != 0){ printf("\nNotification not supported. Query value of characteristic.\n"); gatt_client_read_value_of_characteristic(handle_gatt_client_event, connection_handle, &config_characteristic); } break; default: break; } break; case TC_W4_BATTERY_DATA: switch(hci_event_packet_get_type(packet)){ case GATT_EVENT_NOTIFICATION: printf("\nBattery Data:\n"); dump_characteristic_value(&packet[8], little_endian_read_16(packet, 6)); break; case GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT: if (gatt_event_characteristic_value_query_result_get_value_length(packet) < 1) break; battery_level = gatt_event_characteristic_value_query_result_get_value(packet)[0]; printf("Battry level %d \n", battery_level); break; case GATT_EVENT_QUERY_COMPLETE: if (packet[4] != 0){ printf("CHARACTERISTIC_VALUE_QUERY_RESULT - Error status %x.\n", packet[4]); break; } // Use timer if repeated request is needed and notification is not supperted gap_disconnect(connection_handle); break; default: printf("Unknown packet type %x\n", hci_event_packet_get_type(packet)); break; } break; default: printf("error\n"); break; } }