本文整理汇总了C++中READ_BT_16函数的典型用法代码示例。如果您正苦于以下问题:C++ READ_BT_16函数的具体用法?C++ READ_BT_16怎么用?C++ READ_BT_16使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了READ_BT_16函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: bt_device_btstack_write_device_class
/*
* \brief This function writes the device class for a given device number.
*
* \param devclass the device class to write
*
* \return 0 if successful, -1 otherwise
*/
int bt_device_btstack_write_device_class(int ignored, uint32_t devclass)
{
int ret = btstack_common_send_cmd(&btstack_hci_write_class_of_device, devclass);
while(ret >= 0)
{
ret = btstack_common_recv_packet(&recv_data);
if(ret > 0)
{
int type = READ_BT_16(recv_data.buffer, 0);
unsigned char* packet = recv_data.buffer+sizeof(packet_header_t);
if(type == HCI_EVENT_PACKET)
{
if ( COMMAND_COMPLETE_EVENT(packet, btstack_hci_write_class_of_device) ) {
break;
}
}
}
}
return ret;
}
开发者ID:code4bones,项目名称:GIMX,代码行数:29,代码来源:bt_device_btstack.c
示例2: handle_prepare_write_request
//
// MARK: ATT_PREPARE_WRITE_REQUEST 0x16
static uint16_t handle_prepare_write_request(uint8_t * request_buffer, uint16_t request_len,
uint8_t * response_buffer, uint16_t response_buffer_size){
uint16_t handle = READ_BT_16(request_buffer, 1);
if (!att_write_callback) {
// TODO: Use "Write Not Permitted"
return setup_error_atribute_not_found(response_buffer, ATT_PREPARE_WRITE_REQUEST, handle);
}
att_iterator_t it;
int ok = att_find_handle(&it, handle);
if (!ok) {
return setup_error_atribute_not_found(response_buffer, ATT_WRITE_REQUEST, handle);
}
if ((it.flags & ATT_PROPERTY_DYNAMIC) == 0) {
// TODO: Use "Write Not Permitted"
return setup_error_atribute_not_found(response_buffer, ATT_WRITE_REQUEST, handle);
}
(*att_write_callback)(handle, ATT_TRANSACTION_MODE_ACTIVE, 0, request_buffer + 3, request_len - 3, NULL);
// response: echo request
memcpy(response_buffer, request_buffer, request_len);
response_buffer[0] = ATT_PREPARE_WRITE_RESPONSE;
return request_len;
}
开发者ID:13hoop,项目名称:limo,代码行数:25,代码来源:att.c
示例3: comm_packet_handler
//.........这里部分代码省略.........
if (msc_resp_send && msc_resp_received) {
send_credits_packet = 1;
msc_resp_send = msc_resp_received = 0;
printf("RFCOMM up and running!\n");
}
if (send_credits_packet) {
// send 0x30 credits
uint8_t initiator = 1;
uint8_t address = (1 << 0) | (initiator << 1) | (initiator << 1) | (RFCOMM_CHANNEL_ID << 3);
rfcomm_send_packet(source_cid, address, BT_RFCOMM_UIH_PF, NR_CREDITS, NULL, 0);
}
if (!packet_processed){
// just dump data for now
printf("??: address %02x, control %02x: ", packet[0], packet[1]);
hexdump( packet, size );
}
break;
case HCI_EVENT_PACKET:
switch (packet[0]) {
case BTSTACK_EVENT_POWERON_FAILED:
// handle HCI init failure
printf("HCI Init failed - make sure you have turned off Bluetooth in the System Settings\n");
exit(1);
break;
case BTSTACK_EVENT_STATE:
// bt stack activated, get started - use authentication yes/no
if (packet[2] == HCI_STATE_WORKING) {
bt_send_cmd(&hci_write_authentication_enable, 1);
}
break;
case HCI_EVENT_LINK_KEY_REQUEST:
// link key request
bt_flip_addr(event_addr, &packet[2]);
bt_send_cmd(&hci_link_key_request_negative_reply, &event_addr);
break;
case HCI_EVENT_PIN_CODE_REQUEST:
// inform about pin code request
bt_flip_addr(event_addr, &packet[2]);
bt_send_cmd(&hci_pin_code_request_reply, &event_addr, 4, PIN);
printf("Please enter PIN %s on remote device\n", PIN);
break;
case L2CAP_EVENT_CHANNEL_OPENED:
// inform about new l2cap connection
bt_flip_addr(event_addr, &packet[3]);
uint16_t psm = READ_BT_16(packet, 11);
source_cid = READ_BT_16(packet, 13);
con_handle = READ_BT_16(packet, 9);
if (packet[2] == 0) {
printf("Channel successfully opened: ");
print_bd_addr(event_addr);
printf(", handle 0x%02x, psm 0x%02x, source cid 0x%02x, dest cid 0x%02x\n",
con_handle, psm, source_cid, READ_BT_16(packet, 15));
// send SABM command on dlci 0
printf("Sending SABM #0\n");
_bt_rfcomm_send_sabm(source_cid, 1, 0);
} else {
printf("L2CAP connection to device ");
print_bd_addr(event_addr);
printf(" failed. status code %u\n", packet[2]);
exit(1);
}
break;
case HCI_EVENT_DISCONNECTION_COMPLETE:
// connection closed -> quit test app
printf("Basebank connection closed, exit.\n");
exit(0);
break;
case HCI_EVENT_COMMAND_COMPLETE:
// connect to RFCOMM device (PSM 0x03) at addr
if ( COMMAND_COMPLETE_EVENT(packet, hci_write_authentication_enable) ) {
bt_send_cmd(&l2cap_create_channel, addr, 0x03);
}
break;
default:
// unhandled event
if(DEBUG) printf("unhandled event : %02x\n", packet[0]);
break;
}
break;
default:
// unhandled packet type
if(DEBUG) printf("unhandled packet type : %02x\n", packet_type);
break;
}
}
开发者ID:darkfall,项目名称:ArduinoBot,代码行数:101,代码来源:BTLayer.c
示例4: att_event_packet_handler
static void att_event_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
switch (packet_type) {
case HCI_EVENT_PACKET:
switch (packet[0]) {
case DAEMON_EVENT_HCI_PACKET_SENT:
att_run();
break;
case HCI_EVENT_LE_META:
switch (packet[2]) {
case HCI_SUBEVENT_LE_CONNECTION_COMPLETE:
// store connection info
att_client_addr_type = packet[7];
bt_flip_addr(att_client_address, &packet[8]);
// reset connection properties
att_connection.con_handle = READ_BT_16(packet, 4);
att_connection.mtu = ATT_DEFAULT_MTU;
att_connection.max_mtu = l2cap_max_le_mtu();
att_connection.encryption_key_size = 0;
att_connection.authenticated = 0;
att_connection.authorized = 0;
break;
default:
break;
}
break;
case HCI_EVENT_ENCRYPTION_CHANGE:
// check handle
if (att_connection.con_handle != READ_BT_16(packet, 3)) break;
att_connection.encryption_key_size = sm_encryption_key_size(att_client_addr_type, att_client_address);
att_connection.authenticated = sm_authenticated(att_client_addr_type, att_client_address);
break;
case HCI_EVENT_DISCONNECTION_COMPLETE:
att_clear_transaction_queue(&att_connection);
att_connection.con_handle = 0;
att_handle_value_indication_handle = 0; // reset error state
// restart advertising if we have been connected before
// -> avoid sending advertise enable a second time before command complete was received
att_server_state = ATT_SERVER_IDLE;
break;
case SM_IDENTITY_RESOLVING_STARTED:
log_info("SM_IDENTITY_RESOLVING_STARTED");
att_ir_lookup_active = 1;
break;
case SM_IDENTITY_RESOLVING_SUCCEEDED:
att_ir_lookup_active = 0;
att_ir_le_device_db_index = ((sm_event_t*) packet)->le_device_db_index;
log_info("SM_IDENTITY_RESOLVING_SUCCEEDED id %u", att_ir_le_device_db_index);
att_run();
break;
case SM_IDENTITY_RESOLVING_FAILED:
log_info("SM_IDENTITY_RESOLVING_FAILED");
att_ir_lookup_active = 0;
att_ir_le_device_db_index = -1;
att_run();
break;
case SM_AUTHORIZATION_RESULT: {
sm_event_t * event = (sm_event_t *) packet;
if (event->addr_type != att_client_addr_type) break;
if (memcmp(event->address, att_client_address, 6) != 0) break;
att_connection.authorized = event->authorization_result;
att_run();
break;
}
default:
break;
}
}
if (att_client_packet_handler){
att_client_packet_handler(packet_type, channel, packet, size);
}
}
开发者ID:JochenDing,项目名称:btstack,代码行数:81,代码来源:att_server.c
示例5: packet_handler
/*************** PANU client routines *********************/
static void packet_handler (void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)
{
uint8_t event;
bd_addr_t event_addr;
bd_addr_t src_addr;
bd_addr_t dst_addr;
uint16_t uuid_source;
uint16_t uuid_dest;
uint16_t mtu;
uint16_t network_type;
uint8_t protocol_type;
uint8_t icmp_type;
int ihl;
int payload_offset;
switch (packet_type) {
case HCI_EVENT_PACKET:
event = packet[0];
switch (event) {
case BTSTACK_EVENT_STATE:
/* BT Stack activated, get started */
if (packet[2] == HCI_STATE_WORKING) {
printf("BNEP Test ready\n");
show_usage();
}
break;
case HCI_EVENT_COMMAND_COMPLETE:
if (COMMAND_COMPLETE_EVENT(packet, hci_read_bd_addr)){
bt_flip_addr(local_addr, &packet[6]);
printf("BD-ADDR: %s\n", bd_addr_to_str(local_addr));
break;
}
break;
case HCI_EVENT_USER_CONFIRMATION_REQUEST:
// inform about user confirmation request
printf("SSP User Confirmation Request with numeric value '%06u'\n", READ_BT_32(packet, 8));
printf("SSP User Confirmation Auto accept\n");
break;
case BNEP_EVENT_OPEN_CHANNEL_COMPLETE:
if (packet[2]) {
printf("BNEP channel open failed, status %02x\n", packet[2]);
} else {
// data: event(8), len(8), status (8), bnep source uuid (16), bnep destination uuid (16), remote_address (48)
uuid_source = READ_BT_16(packet, 3);
uuid_dest = READ_BT_16(packet, 5);
mtu = READ_BT_16(packet, 7);
bnep_cid = channel;
//bt_flip_addr(event_addr, &packet[9]);
memcpy(&event_addr, &packet[9], sizeof(bd_addr_t));
printf("BNEP connection open succeeded to %s source UUID 0x%04x dest UUID: 0x%04x, max frame size %u\n", bd_addr_to_str(event_addr), uuid_source, uuid_dest, mtu);
}
break;
case BNEP_EVENT_CHANNEL_TIMEOUT:
printf("BNEP channel timeout! Channel will be closed\n");
break;
case BNEP_EVENT_CHANNEL_CLOSED:
printf("BNEP channel closed\n");
break;
case BNEP_EVENT_READY_TO_SEND:
/* Check for parked network packets and send it out now */
if (network_buffer_len > 0) {
bnep_send(bnep_cid, network_buffer, network_buffer_len);
network_buffer_len = 0;
}
break;
default:
break;
}
break;
case BNEP_DATA_PACKET:
// show received packet on console
// TODO: fix BNEP to return BD ADDR in little endian, to use these lines
// bt_flip_addr(dst_addr, &packet[0]);
// bt_flip_addr(src_addr, &packet[6]);
// instead of these
memcpy(dst_addr, &packet[0], 6);
memcpy(src_addr, &packet[6], 6);
// END TOOD
network_type = READ_NET_16(packet, 12);
printf("BNEP packet received\n");
printf("Dst Addr: %s\n", bd_addr_to_str(dst_addr));
printf("Src Addr: %s\n", bd_addr_to_str(src_addr));
printf("Net Type: %04x\n", network_type);
// ignore the next 60 bytes
// hexdumpf(&packet[74], size - 74);
switch (network_type){
case NETWORK_TYPE_IPv4:
ihl = packet[14] & 0x0f;
payload_offset = 14 + (ihl << 2);
// protocol
//.........这里部分代码省略.........
开发者ID:hearingthings,项目名称:btstack,代码行数:101,代码来源:bnep_test.c
示例6: h4_block_received
// potentially called from ISR context
static void h4_block_received(void){
read_pos += bytes_to_read;
// act
switch (h4_state) {
case H4_W4_PACKET_TYPE:
switch (hci_packet[0]) {
case HCI_ACL_DATA_PACKET:
h4_state = H4_W4_ACL_HEADER;
bytes_to_read = HCI_ACL_HEADER_SIZE;
break;
case HCI_EVENT_PACKET:
h4_state = H4_W4_EVENT_HEADER;
bytes_to_read = HCI_EVENT_HEADER_SIZE;
break;
case EHCILL_GO_TO_SLEEP_IND:
case EHCILL_GO_TO_SLEEP_ACK:
case EHCILL_WAKE_UP_IND:
case EHCILL_WAKE_UP_ACK:
ehcill_handle(hci_packet[0]);
h4_rx_init_sm();
return;
default:
log_error("h4_process: invalid packet type 0x%02x", hci_packet[0]);
h4_rx_init_sm();
return;
}
break;
case H4_W4_EVENT_HEADER:
bytes_to_read = hci_packet[2];
// check ACL length
if (HCI_ACL_HEADER_SIZE + bytes_to_read > HCI_PACKET_BUFFER_SIZE){
log_error("h4_process: invalid ACL payload len %u - only space for %u", bytes_to_read, HCI_PACKET_BUFFER_SIZE - HCI_ACL_HEADER_SIZE);
h4_rx_init_sm();
return;
}
if (bytes_to_read) {
h4_state = H4_W4_PAYLOAD;
break;
}
h4_state = H4_PACKET_RECEIVED;
break;
case H4_W4_ACL_HEADER:
bytes_to_read = READ_BT_16( hci_packet, 3);
if (bytes_to_read) {
h4_state = H4_W4_PAYLOAD;
break;
}
h4_state = H4_PACKET_RECEIVED;
break;
case H4_W4_PAYLOAD:
h4_state = H4_PACKET_RECEIVED;
bytes_to_read = 0;
// trigger run loop - necessary for use in low power modes
embedded_trigger();
break;
default:
bytes_to_read = 0;
break;
}
// read next block
if (bytes_to_read) {
ehcill_uart_dma_receive_block(&hci_packet[read_pos], bytes_to_read);
}
// gpio_clear(GPIOB, GPIO_DEBUG_0);
}
开发者ID:Mechelix,项目名称:btstack,代码行数:75,代码来源:hci_transport_h4_ehcill_dma.c
示例7: l2cap_signaling_handler_channel
void l2cap_signaling_handler_channel(l2cap_channel_t *channel, uint8_t *command){
uint8_t code = command[L2CAP_SIGNALING_COMMAND_CODE_OFFSET];
uint8_t identifier = command[L2CAP_SIGNALING_COMMAND_SIGID_OFFSET];
uint16_t result = 0;
log_info("L2CAP signaling handler code %u, state %u\n", code, channel->state);
// handle DISCONNECT REQUESTS seperately
if (code == DISCONNECTION_REQUEST){
switch (channel->state){
case L2CAP_STATE_CONFIG:
case L2CAP_STATE_OPEN:
case L2CAP_STATE_WILL_SEND_DISCONNECT_REQUEST:
case L2CAP_STATE_WAIT_DISCONNECT:
l2cap_handle_disconnect_request(channel, identifier);
break;
default:
// ignore in other states
break;
}
return;
}
// @STATEMACHINE(l2cap)
switch (channel->state) {
case L2CAP_STATE_WAIT_CONNECT_RSP:
switch (code){
case CONNECTION_RESPONSE:
result = READ_BT_16 (command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET+4);
switch (result) {
case 0:
// successful connection
channel->remote_cid = READ_BT_16(command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET);
channel->state = L2CAP_STATE_CONFIG;
channelStateVarSetFlag(channel, L2CAP_CHANNEL_STATE_VAR_SEND_CONF_REQ);
break;
case 1:
// connection pending. get some coffee
break;
default:
// channel closed
channel->state = L2CAP_STATE_CLOSED;
// map l2cap connection response result to BTstack status enumeration
l2cap_emit_channel_opened(channel, L2CAP_CONNECTION_RESPONSE_RESULT_SUCCESSFUL + result);
// drop link key if security block
if (L2CAP_CONNECTION_RESPONSE_RESULT_SUCCESSFUL + result == L2CAP_CONNECTION_RESPONSE_RESULT_REFUSED_SECURITY){
hci_drop_link_key_for_bd_addr(&channel->address);
}
// discard channel
linked_list_remove(&l2cap_channels, (linked_item_t *) channel);
btstack_memory_l2cap_channel_free(channel);
break;
}
break;
default:
//@TODO: implement other signaling packets
break;
}
break;
case L2CAP_STATE_CONFIG:
switch (code) {
case CONFIGURE_REQUEST:
channelStateVarSetFlag(channel, L2CAP_CHANNEL_STATE_VAR_RCVD_CONF_REQ);
channelStateVarSetFlag(channel, L2CAP_CHANNEL_STATE_VAR_SEND_CONF_RSP);
l2cap_signaling_handle_configure_request(channel, command);
break;
case CONFIGURE_RESPONSE:
channelStateVarSetFlag(channel, L2CAP_CHANNEL_STATE_VAR_RCVD_CONF_RSP);
break;
default:
break;
}
if (l2cap_channel_ready_for_open(channel)){
// for open:
channel->state = L2CAP_STATE_OPEN;
l2cap_emit_channel_opened(channel, 0);
l2cap_emit_credits(channel, 1);
}
break;
case L2CAP_STATE_WAIT_DISCONNECT:
switch (code) {
case DISCONNECTION_RESPONSE:
l2cap_finialize_channel_close(channel);
break;
default:
//@TODO: implement other signaling packets
break;
}
break;
case L2CAP_STATE_CLOSED:
//.........这里部分代码省略.........
开发者ID:Simu3,项目名称:RobotLog,代码行数:101,代码来源:l2cap.c
示例8: handle_hci_event
static void handle_hci_event(uint8_t packet_type, uint8_t *packet, uint16_t size){
le_command_status_t status;
if (packet_type != HCI_EVENT_PACKET) return;
switch (packet[0]) {
case HCI_EVENT_DISCONNECTION_COMPLETE:
printf("test client - DISCONNECTED\n");
break;
case GAP_LE_ADVERTISING_REPORT:
if (tc_state != TC_W4_SCAN_RESULT) return;
printf("test client - SCAN ACTIVE\n");
ad_event_t ad_event;
int pos = 2;
ad_event.event_type = packet[pos++];
ad_event.address_type = packet[pos++];
memcpy(ad_event.address, &packet[pos], 6);
pos += 6;
ad_event.rssi = packet[pos++];
ad_event.length = packet[pos++];
ad_event.data = &packet[pos];
pos += ad_event.length;
dump_ad_event(&ad_event);
test_device_addr_type = ad_event.address_type;
bd_addr_t found_device_addr;
memcpy(found_device_addr, ad_event.address, 6);
swapX(ad_event.address, found_device_addr, 6);
if (memcmp(&found_device_addr, &sensor_tag1_addr, 6) == 0
|| memcmp(&found_device_addr, &sensor_tag2_addr, 6) == 0) {
tc_state = TC_W4_CONNECT;
le_central_stop_scan();
le_central_connect(&found_device_addr, test_device_addr_type);
}
break;
case BTSTACK_EVENT_STATE:
// BTstack activated, get started
if (packet[2] == HCI_STATE_WORKING) {
printf("BTstack activated, get started!\n");
tc_state = TC_W4_SCAN_RESULT;
le_central_start_scan();
}
break;
case HCI_EVENT_LE_META:
switch (packet[2]) {
case HCI_SUBEVENT_LE_CONNECTION_COMPLETE: {
if (tc_state != TC_W4_CONNECT) return;
tc_state = TC_W4_SERVICE_RESULT;
printf("\n test client - CONNECTED, query ACC service\n");
test_gatt_client_handle = READ_BT_16(packet, 4);
gatt_client_start(&test_gatt_client_context, test_gatt_client_handle);
// let's start
gatt_client_discover_primary_services_by_uuid128(&test_gatt_client_context, acc_service_uuid);
break;
}
default:
break;
}
break;
case DAEMON_EVENT_HCI_PACKET_SENT:
switch(tc_state){
case TC_W2_WRITE_WITHOUT_RESPONSE:
status = gatt_client_write_value_of_characteristic_without_response(&test_gatt_client_context, characteristic.value_handle, 1, chr_short_value);
if (status != BLE_PERIPHERAL_OK) break;
tc_state = TC_W4_READ_LONG_RESULT;
gatt_client_read_long_value_of_characteristic(&test_gatt_client_context, &characteristic);
default:
break;
}
default:
break;
}
}
开发者ID:matlo,项目名称:btstack,代码行数:80,代码来源:ble_client.c
示例9: packet_handler
void packet_handler(uint8_t * event, uint16_t event_size){
if (event[0] == RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE){
handle = READ_BT_16(event, 9);
printf("RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE received for handle 0x%04x\n", handle);
return;
}
if (event[0] != HCI_EVENT_HFP_META) return;
if (event[3]
&& event[2] != HFP_SUBEVENT_PLACE_CALL_WITH_NUMBER
&& event[2] != HFP_SUBEVENT_ATTACH_NUMBER_TO_VOICE_TAG
&& event[2] != HFP_SUBEVENT_TRANSMIT_DTMF_CODES
&& event[2] != HFP_SUBEVENT_TRANSMIT_STATUS_OF_CURRENT_CALL){
printf("ERROR, status: %u\n", event[3]);
return;
}
switch (event[2]) {
case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED:
printf("Service level connection established.\n");
break;
case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED:
printf("Service level connection released.\n");
break;
case HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED:
printf("\n** Audio connection established **\n");
break;
case HFP_SUBEVENT_AUDIO_CONNECTION_RELEASED:
printf("\n** Audio connection released **\n");
break;
case HFP_SUBEVENT_START_RINGINIG:
printf("\n** Start Ringing **\n");
break;
case HFP_SUBEVENT_STOP_RINGINIG:
printf("\n** Stop Ringing **\n");
break;
case HFP_SUBEVENT_PLACE_CALL_WITH_NUMBER:
printf("\n** Outgoing call '%s' **\n", &event[3]);
// validate number
if ( strcmp("1234567", (char*) &event[3]) == 0
|| strcmp("7654321", (char*) &event[3]) == 0
|| (memory_1_enabled && strcmp(">1", (char*) &event[3]) == 0)){
printf("Dialstring valid: accept call\n");
hfp_ag_outgoing_call_accepted();
// TODO: calling ringing right away leads to callstatus=2 being skipped. don't call for now
// hfp_ag_outgoing_call_ringing();
} else {
printf("Dialstring invalid: reject call\n");
hfp_ag_outgoing_call_rejected();
}
break;
case HFP_SUBEVENT_REDIAL_LAST_NUMBER:
printf("\n** Redial last number\n");
if (last_number_exists){
hfp_ag_outgoing_call_accepted();
printf("Last number exists: accept call\n");
// TODO: calling ringing right away leads to callstatus=2 being skipped. don't call for now
// hfp_ag_outgoing_call_ringing();
} else {
printf("Last number missing: reject call\n");
hfp_ag_outgoing_call_rejected();
}
break;
case HFP_SUBEVENT_ATTACH_NUMBER_TO_VOICE_TAG:
printf("\n** Attach number to voice tag. Sending '1234567\n");
hfp_ag_send_phone_number_for_voice_tag(device_addr, "1234567");
break;
case HFP_SUBEVENT_TRANSMIT_DTMF_CODES:
printf("\n** Send DTMF Codes: '%s'\n", &event[3]);
hfp_ag_send_dtmf_code_done(device_addr);
break;
case HFP_SUBEVENT_TRANSMIT_STATUS_OF_CURRENT_CALL:
if (current_call_index == 0 && current_call_exists_a){
printf("HFP_SUBEVENT_TRANSMIT_STATUS_OF_CURRENT_CALL 1\n");
hfp_ag_send_current_call_status(device_addr, 1, current_call_dir, current_call_status_a,
HFP_ENHANCED_CALL_MODE_VOICE, current_call_mpty, 129, "1234567");
current_call_index = 1;
break;
}
if (current_call_index == 1 && current_call_exists_b){
printf("HFP_SUBEVENT_TRANSMIT_STATUS_OF_CURRENT_CALL 2 \n");
hfp_ag_send_current_call_status(device_addr, 2, current_call_dir, current_call_status_b,
HFP_ENHANCED_CALL_MODE_VOICE, current_call_mpty, 129, "7654321");
current_call_index = 2;
break;
}
printf("HFP_SUBEVENT_TRANSMIT_STATUS_OF_CURRENT_CALL 3\n");
hfp_ag_send_current_call_status_done(device_addr);
break;
case HFP_CMD_CALL_ANSWERED:
printf("Call answered by HF\n");
if (current_call_status_a == HFP_ENHANCED_CALL_STATUS_INCOMING){
current_call_status_a = HFP_ENHANCED_CALL_STATUS_ACTIVE;
}
if (current_call_status_b == HFP_ENHANCED_CALL_STATUS_INCOMING){
current_call_status_b = HFP_ENHANCED_CALL_STATUS_ACTIVE;
}
break;
//.........这里部分代码省略.........
开发者ID:cplmaomao,项目名称:btstack,代码行数:101,代码来源:hfp_ag_client_test.c
示例10: att_write_callback
/* LISTING_START(attWrite): ATT Write */
static int att_write_callback(uint16_t con_handle, uint16_t att_handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size){
if (att_handle != ATT_CHARACTERISTIC_0000FF11_0000_1000_8000_00805F9B34FB_01_CLIENT_CONFIGURATION_HANDLE) return 0;
le_notification_enabled = READ_BT_16(buffer, 0) == GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION;
test_reset();
return 0;
}
开发者ID:orglaoying,项目名称:btstack,代码行数:7,代码来源:le_streamer.c
示例11: btpad_packet_handler
void btpad_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)
{
bd_addr_t event_addr;
if (packet_type == HCI_EVENT_PACKET)
{
switch (packet[0])
{
case BTSTACK_EVENT_STATE:
{
RARCH_LOG("BTstack: HCI State %d\n", packet[2]);
switch (packet[2])
{
case HCI_STATE_WORKING:
btpad_queue_reset();
btpad_queue_hci_read_bd_addr();
bt_send_cmd_ptr(l2cap_register_service_ptr, PSM_HID_CONTROL, 672); // TODO: Where did I get 672 for mtu?
bt_send_cmd_ptr(l2cap_register_service_ptr, PSM_HID_INTERRUPT, 672);
btpad_queue_hci_inquiry(HCI_INQUIRY_LAP, 3, 1);
btpad_queue_run(1);
break;
case HCI_STATE_HALTING:
btpad_close_all_connections();
CFRunLoopStop(CFRunLoopGetCurrent());
break;
}
}
break;
case HCI_EVENT_COMMAND_STATUS:
btpad_queue_run(packet[3]);
break;
case HCI_EVENT_COMMAND_COMPLETE:
{
btpad_queue_run(packet[2]);
if (COMMAND_COMPLETE_EVENT(packet, (*hci_read_bd_addr_ptr)))
{
bt_flip_addr_ptr(event_addr, &packet[6]);
if (!packet[5])
RARCH_LOG("BTpad: Local address is %s\n", bd_addr_to_str_ptr(event_addr));
else
RARCH_LOG("BTpad: Failed to get local address (Status: %02X)\n", packet[5]);
}
}
break;
case HCI_EVENT_INQUIRY_RESULT:
{
if (packet[2])
{
bt_flip_addr_ptr(event_addr, &packet[3]);
struct apple_pad_connection* connection = (struct apple_pad_connection*)btpad_find_empty_connection();
if (connection)
{
RARCH_LOG("BTpad: Inquiry found device\n");
memset(connection, 0, sizeof(struct apple_pad_connection));
memcpy(connection->address, event_addr, sizeof(bd_addr_t));
connection->has_address = true;
connection->state = BTPAD_CONNECTING;
bt_send_cmd_ptr(l2cap_create_channel_ptr, connection->address, PSM_HID_CONTROL);
bt_send_cmd_ptr(l2cap_create_channel_ptr, connection->address, PSM_HID_INTERRUPT);
}
}
}
break;
case HCI_EVENT_INQUIRY_COMPLETE:
{
// This must be turned off during gameplay as it causes a ton of lag
inquiry_running = !inquiry_off;
if (inquiry_running)
btpad_queue_hci_inquiry(HCI_INQUIRY_LAP, 3, 1);
}
break;
case L2CAP_EVENT_CHANNEL_OPENED:
{
bt_flip_addr_ptr(event_addr, &packet[3]);
const uint16_t handle = READ_BT_16(packet, 9);
const uint16_t psm = READ_BT_16(packet, 11);
const uint16_t channel_id = READ_BT_16(packet, 13);
struct apple_pad_connection* connection = (struct apple_pad_connection*)btpad_find_connection_for(handle, event_addr);
if (!packet[2])
{
if (!connection)
{
RARCH_LOG("BTpad: Got L2CAP 'Channel Opened' event for unrecognized device\n");
//.........这里部分代码省略.........
开发者ID:ChowZenki,项目名称:RetroArch,代码行数:101,代码来源:btpad.c
示例12: DES
/*
parse the sdp record:
type DES (6), element len 26
type DES (6), element len 24
type UINT (1), element len 3 , value: 0x00000004
type DES (6), element len 19
type DES (6), element len 5
type UUID (3), element len 3 , value: 0x00000100
type DES (6), element len 7
type UUID (3), element len 3 , value: 0x00000003
type UINT (1), element len 2 , value: 0x00000002
type DES (6), element len 5
type UUID (3), element len 3 , value: 0x00000008
*/
static void sdpc_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)
{
if (packet_type == HCI_EVENT_PACKET)
{
switch(packet[0]){
case L2CAP_EVENT_CHANNEL_OPENED:
{
if (packet[2]) {
log_info("Connection failed\n");
return;
}
log_info("Connected\n");
state = SENDING;
current_server = 0;
l2cap_cid = READ_BT_16(packet, 13);
sdpc_trysend();
break;
}
case DAEMON_EVENT_HCI_PACKET_SENT:
case L2CAP_EVENT_CREDITS:
{
sdpc_trysend();
break;
}
case L2CAP_EVENT_CHANNEL_CLOSED:
if (channel == l2cap_cid){
// reset
l2cap_cid = 0;
}
break;
}
}
if (packet_type == L2CAP_DATA_PACKET){
log_info("SDP Respone %d \n", READ_NET_16(packet, 5));
//de_dump_data_element(&packet[7]);
//check if valid answer returns
if (READ_NET_16(packet, 5) > 2)
{
switch(current_server)
{
case 0:
{
hfp_port = sdp_get_parameters_for_uuid(&packet[7], 0x0003);;
log_info("hfp port: %d\n", hfp_port);
break;
}
case 1:
break;
case 2:
{
mas_port = sdp_get_parameters_for_uuid(&packet[7], 0x0003);;
log_info("MAP port: %d\n", mas_port );
break;
}
}
}
current_server++;
if (current_server == 3)
{
state = DONE;
l2cap_close_connection(¤t_server);
if (hfp_port != 0)
hfp_open(&addr, hfp_port);
// if (mas_port != 0)
// mas_open(&addr, mas_port);
}
else
{
state = SENDING;
sdpc_trysend();
}
}
}
开发者ID:Echoskope,项目名称:KreyosFirmware,代码行数:90,代码来源:sdp_client.c
示例13: handle_read_by_group_type_request
static uint16_t handle_read_by_group_type_request(att_connection_t * att_connection, uint8_t * request_buffer, uint16_t request_len,
uint8_t * response_buffer, uint16_t response_buffer_size){
int attribute_type_len;
if (request_len <= 7){
attribute_type_len = 2;
} else {
attribute_type_len = 16;
}
return handle_read_by_group_type_request2(att_connection, response_buffer, response_buffer_size, READ_BT_16(request_buffer, 1), READ_BT_16(request_buffer, 3), attribute_type_len, &request_buffer[5]);
}
开发者ID:Mechelix,项目名称:btstack,代码行数:10,代码来源:att.c
示例14: handle_read_blob_request
static uint16_t handle_read_blob_request(att_connection_t * att_connection, uint8_t * request_buffer, uint16_t request_len,
uint8_t * response_buffer, uint16_t response_buffer_size){
return handle_read_blob_request2(att_connection, response_buffer, response_buffer_size, READ_BT_16(request_buffer, 1), READ_BT_16(request_buffer, 3));
}
开发者ID:Mechelix,项目名称:btstack,代码行数:4,代码来源:att.c
示例15: uuid16_from_uuid
static uint16_t uuid16_from_uuid(uint16_t uuid_len, uint8_t * uuid){
if (uuid_len == 2) return READ_BT_16(uuid, 0);
if (!is_Bluetooth_Base_UUID(uuid)) return 0;
return READ_BT_16(uuid, 12);
}
开发者ID:Mechelix,项目名称:btstack,代码行数:5,代码来源:att.c
示例16: handle_gatt_client_event
static void handle_gatt_client_event(le_event_t * event) {
uint8_t * packet = (uint8_t*) event;
int connection_encrypted;
// handle connect / disconncet events first
switch (packet[0]) {
case HCI_EVENT_LE_META:
switch (packet[2]) {
case HCI_SUBEVENT_LE_CONNECTION_COMPLETE:
gc_handle = READ_BT_16(packet, 4);
printf("Connection handle 0x%04x, request encryption\n", gc_handle);
// we need to be paired to enable notifications
tc_state = TC_W4_ENCRYPTED_CONNECTION;
sm_send_security_request(gc_handle);
break;
default:
break;
}
return;
case HCI_EVENT_ENCRYPTION_CHANGE:
if (gc_handle != READ_BT_16(packet, 3)) return;
connection_encrypted = packet[5];
log_info("Encryption state change: %u", connection_encrypted);
if (!connection_encrypted) return;
if (tc_state != TC_W4_ENCRYPTED_CONNECTION) return;
// let's start
printf("\nANCS Client - CONNECTED, discover ANCS service\n");
tc_state = TC_W4_SERVICE_RESULT;
gatt_client_discover_primary_services_by_uuid128(gc_id, gc_handle, ancs_service_uuid);
return;
case HCI_EVENT_DISCONNECTION_COMPLETE:
notify_client(ANCS_CLIENT_DISCONNECTED);
return;
default:
break;
}
le_characteristic_t characteristic;
le_characteristic_value_event_t * value_event;
switch(tc_state) {
case TC_W4_SERVICE_RESULT:
switch(event->type) {
case GATT_SERVICE_QUERY_RESULT:
ancs_service = ((le_service_event_t *) event)->service;
ancs_service_found = 1;
break;
case GATT_QUERY_COMPLETE:
if (!ancs_service_found) {
printf("ANCS Service not found");
tc_state = TC_IDLE;
break;
}
tc_state = TC_W4_CHARACTERISTIC_RESULT;
printf("ANCS Client - Discover characteristics for ANCS SERVICE \n");
gatt_client_discover_characteristics_for_service(gc_id, gc_handle, &ancs_service);
break;
default:
break;
}
break;
case TC_W4_CHARACTERISTIC_RESULT:
switch(event->type) {
case GATT_CHARACTERISTIC_QUERY_RESULT:
characteristic = ((le_characteristic_event_t *) event)->characteristic;
if (memcmp(characteristic.uuid128, ancs_notification_source_uuid, 16) == 0) {
printf("ANCS Notification Source Characterisic found\n");
ancs_notification_source_characteristic = characteristic;
ancs_characteristcs++;
break;
}
if (memcmp(characteristic.uuid128, ancs_control_point_uuid, 16) == 0) {
printf("ANCS Control Point found\n");
ancs_control_point_characteristic = characteristic;
ancs_characteristcs++;
break;
}
if (memcmp(characteristic.uuid128, ancs_data_source_uuid, 16) == 0) {
printf("ANCS Data Source Characterisic found\n");
ancs_data_source_characteristic = characteristic;
ancs_characteristcs++;
break;
}
break;
case GATT_QUERY_COMPLETE:
printf("ANCS Characteristcs count %u\n", ancs_characteristcs);
tc_state = TC_W4_NOTIFICATION_SOURCE_SUBSCRIBED;
gatt_client_write_client_characteristic_configuration(gc_id, gc_handle, &ancs_notification_source_characteristic,
GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION);
break;
default:
break;
}
break;
//.........这里部分代码省略.........
开发者ID:redbear,项目名称:btstack,代码行数:101,代码来源:ancs_client_lib.c
示例17: packet_handler
static void packet_handler (void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
//printf("packet_handler type %u, packet[0] %x\n", packet_type, packet[0]);
if (packet_type == RFCOMM_DATA_PACKET){
// skip over leading newline
while (size > 0 && (packet[0] == '\n' || packet[0] == '\r')){
size--;
packet++;
}
if (strncmp((char *)packet, HSP_AG_RING, strlen(HSP_AG_RING)) == 0){
emit_ring_event();
} else if
|
请发表评论