avrcp_controller: emit AVRCP_SUBEVENT_ENABLE_NOTIFICATION_COMPLETE

This commit is contained in:
Milanka Ringwald 2021-10-26 11:25:19 +02:00
parent 2ac1dc76c9
commit bce3db218b
4 changed files with 38 additions and 14 deletions

View File

@ -843,11 +843,20 @@ static void avrcp_controller_packet_handler(uint8_t packet_type, uint16_t channe
switch (packet[2]){
case AVRCP_SUBEVENT_NOTIFICATION_VOLUME_CHANGED:
printf("AVRCP Controller: notification absolute volume changed %d %%\n", avrcp_subevent_notification_volume_changed_get_absolute_volume(packet) * 100 / 127);
printf("AVRCP Controller: Notification Absolute Volume %d %%\n", avrcp_subevent_notification_volume_changed_get_absolute_volume(packet) * 100 / 127);
break;
case AVRCP_SUBEVENT_NOTIFICATION_EVENT_BATT_STATUS_CHANGED:
// see avrcp_battery_status_t
printf("AVRCP Controller: battery status changed %d\n", avrcp_subevent_notification_event_batt_status_changed_get_battery_status(packet));
printf("AVRCP Controller: Notification Battery Status %d\n", avrcp_subevent_notification_event_batt_status_changed_get_battery_status(packet));
break;
case AVRCP_SUBEVENT_ENABLE_NOTIFICATION_COMPLETE:
printf("AVRCP Controller: Notification %s ", avrcp_event2str(avrcp_subevent_enable_notification_complete_get_event_id(packet)));
if (avrcp_subevent_enable_notification_complete_get_status(packet) == ERROR_CODE_SUCCESS){
printf("enabled\n");
} else {
printf("disabled\n");
}
break;
default:
break;

View File

@ -2693,8 +2693,8 @@ typedef uint8_t sm_key_t[16];
* @format 1211
* @param subevent_code
* @param avrcp_cid
* @param command_type
* @param notification_id
* @param status
* @param event_id
*/
#define AVRCP_SUBEVENT_ENABLE_NOTIFICATION_COMPLETE 0x11

View File

@ -8189,21 +8189,21 @@ static inline uint16_t avrcp_subevent_enable_notification_complete_get_avrcp_cid
return little_endian_read_16(event, 3);
}
/**
* @brief Get field command_type from event AVRCP_SUBEVENT_ENABLE_NOTIFICATION_COMPLETE
* @brief Get field status from event AVRCP_SUBEVENT_ENABLE_NOTIFICATION_COMPLETE
* @param event packet
* @return command_type
* @return status
* @note: btstack_type 1
*/
static inline uint8_t avrcp_subevent_enable_notification_complete_get_command_type(const uint8_t * event){
static inline uint8_t avrcp_subevent_enable_notification_complete_get_status(const uint8_t * event){
return event[5];
}
/**
* @brief Get field notification_id from event AVRCP_SUBEVENT_ENABLE_NOTIFICATION_COMPLETE
* @brief Get field event_id from event AVRCP_SUBEVENT_ENABLE_NOTIFICATION_COMPLETE
* @param event packet
* @return notification_id
* @return event_id
* @note: btstack_type 1
*/
static inline uint8_t avrcp_subevent_enable_notification_complete_get_notification_id(const uint8_t * event){
static inline uint8_t avrcp_subevent_enable_notification_complete_get_event_id(const uint8_t * event){
return event[6];
}

View File

@ -92,6 +92,20 @@ static int avrcp_controller_supports_browsing(uint16_t controller_supported_feat
return controller_supported_features & AVRCP_FEATURE_MASK_BROWSING;
}
static void avrcp_controller_emit_notification_complete(avrcp_connection_t * connection, uint8_t status, uint8_t event_id){
uint8_t event[7];
uint8_t pos = 0;
event[pos++] = HCI_EVENT_AVRCP_META;
event[pos++] = sizeof(event) - 2;
event[pos++] = AVRCP_SUBEVENT_ENABLE_NOTIFICATION_COMPLETE;
little_endian_store_16(event, pos, connection->avrcp_cid);
pos += 2;
event[pos++] = status;
event[pos++] = event_id;
UNUSED(pos);
(*avrcp_controller_context.avrcp_callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
}
static void avrcp_controller_emit_supported_events(avrcp_connection_t * connection){
uint8_t ctype = (uint8_t) AVRCP_CTYPE_RESPONSE_CHANGED_STABLE;
uint8_t event_id;
@ -724,8 +738,7 @@ static uint8_t avrcp_controller_request_continue_response(avrcp_connection_t * c
return ERROR_CODE_SUCCESS;
}
static void
avrcp_controller_handle_notification(avrcp_connection_t *connection, avrcp_command_type_t ctype, uint8_t *payload, uint16_t size) {
static void avrcp_controller_handle_notification(avrcp_connection_t *connection, avrcp_command_type_t ctype, uint8_t status, uint8_t *payload, uint16_t size) {
if (size < 1) return;
uint16_t pos = 0;
avrcp_notification_event_id_t event_id = (avrcp_notification_event_id_t) payload[pos++];
@ -736,13 +749,15 @@ avrcp_controller_handle_notification(avrcp_connection_t *connection, avrcp_comma
case AVRCP_CTYPE_RESPONSE_INTERIM:
// register as enabled
connection->notifications_enabled |= event_mask;
avrcp_controller_emit_notification_complete(connection, status, event_id);
// check if initial value is already sent
if ( (connection->initial_status_reported & event_mask) > 0 ){
return;
}
connection->initial_status_reported |= event_mask;
break;
case AVRCP_CTYPE_RESPONSE_CHANGED_STABLE:
// received change, event is considered deregistered
// received change, event is considered de-registered
// we are re-enabling it automatically, if it is not
// explicitly disabled
connection->notifications_enabled &= reset_event_mask;
@ -899,7 +914,7 @@ static void avrcp_handle_l2cap_data_packet_for_signaling_connection(avrcp_connec
// handle asynchronous notifications, without changing state
if (pdu_id == AVRCP_PDU_ID_REGISTER_NOTIFICATION){
avrcp_controller_handle_notification(connection, ctype, packet + pos, size - pos);
avrcp_controller_handle_notification(connection, ctype, ERROR_CODE_SUCCESS, packet + pos, size - pos);
break;
}