gatt_service: use GATTSERVICE as event prefix for GATT services

This commit is contained in:
Milanka Ringwald 2018-11-02 09:29:31 +01:00
parent e2c2b10c79
commit 28e59789a6
6 changed files with 80 additions and 81 deletions

View File

@ -712,14 +712,14 @@ static int cycling_power_service_write_callback(hci_con_handle_t con_handle, uin
instance->con_handle = con_handle;
uint8_t event[5];
int index = 0;
event[index++] = HCI_EVENT_GATT_SERVICE_META;
event[index++] = HCI_EVENT_GATTSERVICE_META;
event[index++] = sizeof(event) - 2;
if (instance->measurement_server_configuration_descriptor_broadcast){
event[index++] = GATT_SERVICE_SUBEVENT_CYCLING_POWER_BROADCAST_START;
event[index++] = GATTSERVICE_SUBEVENT_CYCLING_POWER_BROADCAST_START;
log_info("cycling power: start broadcast");
} else {
event[index++] = GATT_SERVICE_SUBEVENT_CYCLING_POWER_BROADCAST_STOP;
event[index++] = GATTSERVICE_SUBEVENT_CYCLING_POWER_BROADCAST_STOP;
log_info("cycling power: stop broadcast");
}
little_endian_store_16(event, index, con_handle);
@ -877,9 +877,9 @@ static int cycling_power_service_write_callback(hci_con_handle_t con_handle, uin
printf("start offset compensation procedure, enhanced %d\n", (instance->request_opcode == CP_OPCODE_START_ENHANCED_OFFSET_COMPENSATION));
uint8_t event[7];
int index = 0;
event[index++] = HCI_EVENT_GATT_SERVICE_META;
event[index++] = HCI_EVENT_GATTSERVICE_META;
event[index++] = sizeof(event) - 2;
event[index++] = GATT_SERVICE_SUBEVENT_CYCLING_POWER_START_CALIBRATION;
event[index++] = GATTSERVICE_SUBEVENT_CYCLING_POWER_START_CALIBRATION;
little_endian_store_16(event, index, con_handle);
index += 2;
event[index++] = has_feature(CP_FEATURE_FLAG_SENSOR_MEASUREMENT_CONTEXT) == CP_SENSOR_MEASUREMENT_CONTEXT_TORQUE;
@ -1002,10 +1002,10 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
uint8_t event[5];
int index = 0;
event[index++] = HCI_EVENT_GATT_SERVICE_META;
event[index++] = HCI_EVENT_GATTSERVICE_META;
event[index++] = sizeof(event) - 2;
event[index++] = GATT_SERVICE_SUBEVENT_CYCLING_POWER_BROADCAST_STOP;
event[index++] = GATTSERVICE_SUBEVENT_CYCLING_POWER_BROADCAST_STOP;
little_endian_store_16(event, index, con_handle);
index += 2;
(*instance->calibration_callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));

View File

@ -1019,7 +1019,7 @@ typedef uint8_t sm_key_t[16];
#define HCI_EVENT_HID_META 0xEF
#define HCI_EVENT_A2DP_META 0xF0
#define HCI_EVENT_HIDS_META 0xF1
#define HCI_EVENT_GATT_SERVICE_META 0xF2
#define HCI_EVENT_GATTSERVICE_META 0xF2
// Potential other meta groups
// #define HCI_EVENT_BNEP_META 0xxx
@ -2199,19 +2199,19 @@ typedef uint8_t sm_key_t[16];
* @param measurement_type // 0 - force magnitude, 1 - torque magnitude, see cycling_power_sensor_measurement_context_t
* @param is_enhanced
*/
#define GATT_SERVICE_SUBEVENT_CYCLING_POWER_START_CALIBRATION 0x01
#define GATTSERVICE_SUBEVENT_CYCLING_POWER_START_CALIBRATION 0x01
/**
* @format 12
* @param subevent_code
* @param con_handle
*/
#define GATT_SERVICE_SUBEVENT_CYCLING_POWER_BROADCAST_START 0x02
#define GATTSERVICE_SUBEVENT_CYCLING_POWER_BROADCAST_START 0x02
/**
* @format 12
* @param subevent_code
* @param con_handle
*/
#define GATT_SERVICE_SUBEVENT_CYCLING_POWER_BROADCAST_STOP 0x03
#define GATTSERVICE_SUBEVENT_CYCLING_POWER_BROADCAST_STOP 0x03
#endif

View File

@ -69,6 +69,14 @@ static inline uint8_t hci_event_packet_get_type(const uint8_t * event){
return event[0];
}
/***
* @brief Get subevent code for a2dp event
* @param event packet
* @return subevent_code
*/
static inline uint8_t hci_event_a2dp_meta_get_subevent_code(const uint8_t * event){
return event[2];
}
/***
* @brief Get subevent code for ancs event
* @param event packet
@ -85,14 +93,6 @@ static inline uint8_t hci_event_ancs_meta_get_subevent_code(const uint8_t * even
static inline uint8_t hci_event_avdtp_meta_get_subevent_code(const uint8_t * event){
return event[2];
}
/***
* @brief Get subevent code for a2dp event
* @param event packet
* @return subevent_code
*/
static inline uint8_t hci_event_a2dp_meta_get_subevent_code(const uint8_t * event){
return event[2];
}
/***
* @brief Get subevent code for avrcp event
* @param event packet
@ -101,6 +101,14 @@ static inline uint8_t hci_event_a2dp_meta_get_subevent_code(const uint8_t * even
static inline uint8_t hci_event_avrcp_meta_get_subevent_code(const uint8_t * event){
return event[2];
}
/***
* @brief Get subevent code for gattservice event
* @param event packet
* @return subevent_code
*/
static inline uint8_t hci_event_gattservice_meta_get_subevent_code(const uint8_t * event){
return event[2];
}
/***
* @brief Get subevent code for goep event
* @param event packet
@ -117,30 +125,6 @@ static inline uint8_t hci_event_goep_meta_get_subevent_code(const uint8_t * even
static inline uint8_t hci_event_hfp_meta_get_subevent_code(const uint8_t * event){
return event[2];
}
/***
* @brief Get subevent code for hsp event
* @param event packet
* @return subevent_code
*/
static inline uint8_t hci_event_hsp_meta_get_subevent_code(const uint8_t * event){
return event[2];
}
/***
* @brief Get subevent code for pbap event
* @param event packet
* @return subevent_code
*/
static inline uint8_t hci_event_pbap_meta_get_subevent_code(const uint8_t * event){
return event[2];
}
/***
* @brief Get subevent code for le event
* @param event packet
* @return subevent_code
*/
static inline uint8_t hci_event_le_meta_get_subevent_code(const uint8_t * event){
return event[2];
}
/***
* @brief Get subevent code for hid event
* @param event packet
@ -157,6 +141,30 @@ static inline uint8_t hci_event_hid_meta_get_subevent_code(const uint8_t * event
static inline uint8_t hci_event_hids_meta_get_subevent_code(const uint8_t * event){
return event[2];
}
/***
* @brief Get subevent code for hsp event
* @param event packet
* @return subevent_code
*/
static inline uint8_t hci_event_hsp_meta_get_subevent_code(const uint8_t * event){
return event[2];
}
/***
* @brief Get subevent code for le event
* @param event packet
* @return subevent_code
*/
static inline uint8_t hci_event_le_meta_get_subevent_code(const uint8_t * event){
return event[2];
}
/***
* @brief Get subevent code for pbap event
* @param event packet
* @return subevent_code
*/
static inline uint8_t hci_event_pbap_meta_get_subevent_code(const uint8_t * event){
return event[2];
}
/**
* @brief Get field status from event HCI_EVENT_INQUIRY_COMPLETE
* @param event packet
@ -6838,59 +6846,53 @@ static inline uint16_t hids_subevent_exit_suspend_get_con_handle(const uint8_t *
return little_endian_read_16(event, 3);
}
#ifdef ENABLE_BLE
/**
* @brief Get field con_handle from event GATT_SERVICE_SUBEVENT_CYCLING_POWER_START_CALIBRATION
* @brief Get field con_handle from event GATTSERVICE_SUBEVENT_CYCLING_POWER_START_CALIBRATION
* @param event packet
* @return con_handle
* @note: btstack_type 2
*/
static inline uint16_t gatt_service_subevent_cycling_power_start_calibration_get_con_handle(const uint8_t * event){
static inline uint16_t gattservice_subevent_cycling_power_start_calibration_get_con_handle(const uint8_t * event){
return little_endian_read_16(event, 3);
}
/**
* @brief Get field measurement_type from event GATT_SERVICE_SUBEVENT_CYCLING_POWER_START_CALIBRATION
* @brief Get field measurement_type from event GATTSERVICE_SUBEVENT_CYCLING_POWER_START_CALIBRATION
* @param event packet
* @return measurement_type
* @note: btstack_type 1
*/
static inline uint8_t gatt_service_subevent_cycling_power_start_calibration_get_measurement_type(const uint8_t * event){
static inline uint8_t gattservice_subevent_cycling_power_start_calibration_get_measurement_type(const uint8_t * event){
return event[5];
}
/**
* @brief Get field is_enhanced from event GATT_SERVICE_SUBEVENT_CYCLING_POWER_START_CALIBRATION
* @brief Get field is_enhanced from event GATTSERVICE_SUBEVENT_CYCLING_POWER_START_CALIBRATION
* @param event packet
* @return is_enhanced
* @note: btstack_type 1
*/
static inline uint8_t gatt_service_subevent_cycling_power_start_calibration_get_is_enhanced(const uint8_t * event){
static inline uint8_t gattservice_subevent_cycling_power_start_calibration_get_is_enhanced(const uint8_t * event){
return event[6];
}
#endif
#ifdef ENABLE_BLE
/**
* @brief Get field con_handle from event GATT_SERVICE_SUBEVENT_CYCLING_POWER_BROADCAST_START
* @brief Get field con_handle from event GATTSERVICE_SUBEVENT_CYCLING_POWER_BROADCAST_START
* @param event packet
* @return con_handle
* @note: btstack_type 2
*/
static inline uint16_t gatt_service_subevent_cycling_power_broadcast_start_get_con_handle(const uint8_t * event){
static inline uint16_t gattservice_subevent_cycling_power_broadcast_start_get_con_handle(const uint8_t * event){
return little_endian_read_16(event, 3);
}
#endif
#ifdef ENABLE_BLE
/**
* @brief Get field con_handle from event GATT_SERVICE_SUBEVENT_CYCLING_POWER_BROADCAST_STOP
* @brief Get field con_handle from event GATTSERVICE_SUBEVENT_CYCLING_POWER_BROADCAST_STOP
* @param event packet
* @return con_handle
* @note: btstack_type 2
*/
static inline uint16_t gatt_service_subevent_cycling_power_broadcast_stop_get_con_handle(const uint8_t * event){
static inline uint16_t gattservice_subevent_cycling_power_broadcast_stop_get_con_handle(const uint8_t * event){
return little_endian_read_16(event, 3);
}
#endif

View File

@ -368,14 +368,14 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
}
break;
case HCI_EVENT_GATT_SERVICE_META:
case HCI_EVENT_GATTSERVICE_META:
switch (packet[2]){
case GATT_SERVICE_SUBEVENT_CYCLING_POWER_START_CALIBRATION:
measurement_type = gatt_service_subevent_cycling_power_start_calibration_get_measurement_type(packet);
enhanced_calibration = gatt_service_subevent_cycling_power_start_calibration_get_is_enhanced(packet);
case GATTSERVICE_SUBEVENT_CYCLING_POWER_START_CALIBRATION:
measurement_type = gattservice_subevent_cycling_power_start_calibration_get_measurement_type(packet);
enhanced_calibration = gattservice_subevent_cycling_power_start_calibration_get_is_enhanced(packet);
break;
case GATT_SERVICE_SUBEVENT_CYCLING_POWER_BROADCAST_START:
case GATTSERVICE_SUBEVENT_CYCLING_POWER_BROADCAST_START:
printf("start broadcast\n");
// set ADV_NONCONN_IND
pos = cycling_power_get_measurement_adv(adv_int_max, &broadcast_adv[0], sizeof(broadcast_adv));
@ -384,7 +384,7 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
gap_advertisements_set_data(pos, (uint8_t*) broadcast_adv);
gap_advertisements_enable(1);
break;
case GATT_SERVICE_SUBEVENT_CYCLING_POWER_BROADCAST_STOP:
case GATTSERVICE_SUBEVENT_CYCLING_POWER_BROADCAST_STOP:
printf("stop broadcast\n");
gap_advertisements_enable(0);
break;

View File

@ -9,31 +9,32 @@ import os
import btstack_parser as parser
meta_events = [
'A2DP',
'ANCS',
'AVDTP',
'A2DP',
'AVRCP',
'GATTSERVICE',
'GOEP',
'HFP',
'HSP',
'PBAP',
'LE',
'HID',
'HIDS',
'HSP',
'LE',
'PBAP'
]
supported_event_groups = meta_events + [
'ATT',
'BNEP',
'BTSTACK',
'GAP',
'GATT',
'HCI',
'SDP',
'SM',
'HID',
'L2CAP',
'RFCOMM',
'GATT',
'BNEP',
'ATT',
'HID',
'SDP',
'SM'
]
program_info = '''

View File

@ -327,12 +327,8 @@ def create_event(event_name, format, args):
def event_supported(event_name):
parts = event_name.split('_')
if parts[0] == 'GATT' and parts[1] == "SERVICE":
return False
if parts[0] in ['ATT', 'BTSTACK', 'DAEMON', 'L2CAP', 'RFCOMM', 'SDP', 'GATT', 'GAP', 'HCI', 'SM', 'BNEP']:
return True
return
return parts[0] in ['ATT', 'BTSTACK', 'DAEMON', 'L2CAP', 'RFCOMM', 'SDP', 'GATT', 'GAP', 'HCI', 'SM', 'BNEP']
def class_name_for_event(event_name):
return parser.camel_case(event_name.replace('SUBEVENT','EVENT'))