uint32_t sdp_get_service_record_handle(uint8_t * record) { uint8_t * serviceRecordHandleAttribute = sdp_get_attribute_value_for_attribute_id(record, SDP_ServiceRecordHandle); if (!serviceRecordHandleAttribute) return 0; if (de_get_element_type(serviceRecordHandleAttribute) != DE_UINT) return 0; if (de_get_size_type(serviceRecordHandleAttribute) != DE_SIZE_32) return 0; return READ_NET_32(serviceRecordHandleAttribute, 1); }
static void dump_service_search_response(void){ uint16_t nr_services = READ_NET_16(sdp_response_buffer, 7); int i; printf("Nr service handles: %u\n", nr_services); for (i=0; i<nr_services;i++){ printf(" ServiceHandle %x\n", READ_NET_32(sdp_response_buffer, 9+i*4)); } if (sdp_response_buffer[9 + nr_services * 4]){ printf(" Continuation index %u\n", READ_NET_16(sdp_response_buffer, 9+nr_services*4+1)); } else { printf(" Continuation: NO\n"); } }
static void handle_gps_data(stlv_packet pack, element_handle handle) { char type_buf[MAX_ELEMENT_TYPE_BUFSIZE]; uint16_t gps_spd = 0xffff; uint16_t gps_alt = 0xffff; uint32_t gps_dis = 0; element_handle element = get_first_sub_element(pack, handle); while (IS_VALID_STLV_HANDLE(element)) { int type_len = get_element_type(pack, element, type_buf, sizeof(type_buf)); switch (type_buf[0]) { case SUB_TYPE_ACTIVITY_ALT: { uint8_t* data = get_element_data_buffer(pack, element, type_buf, type_len); uint8_t data_size = get_element_data_size(pack, element, type_buf, type_len); log_info("gps.alt=%d:%02x %02x\n", data_size, data[0], data[1]); //gps_alt = *((uint16_t*)data); //gps_alt = htons(gps_alt); gps_alt = READ_NET_16(data, 0); } break; case SUB_TYPE_ACTIVITY_SPD: { uint8_t* data = get_element_data_buffer(pack, element, type_buf, type_len); uint8_t data_size = get_element_data_size(pack, element, type_buf, type_len); log_info("gps.spd=%d:%02x %02x\n", data_size, data[0], data[1]); //gps_spd = *((uint16_t*)data); //gps_spd = htons(gps_spd); gps_spd = READ_NET_16(data, 0); } break; case SUB_TYPE_ACTIVITY_DIS: { uint8_t* data = get_element_data_buffer(pack, element, type_buf, type_len); uint8_t data_size = get_element_data_size(pack, element, type_buf, type_len); log_info("gps.dis=%d:%02x %02x %02x %02x\n", data_size, data[0], data[1], data[2], data[3]); gps_dis = READ_NET_32(data, 0); } break; } element = get_next_sub_element(pack, handle, element); } handle_gps_info(gps_spd, gps_alt, gps_dis); }
void sdp_parser_handle_service_search(uint8_t * data, uint16_t total_count, uint16_t record_handle_count) { int i; for (i=0; i<record_handle_count; i++) { record_handle = READ_NET_32(data, i*4); record_counter++; sdp_query_service_record_handle_event_t service_record_handle_event = { SDP_QUERY_SERVICE_RECORD_HANDLE, total_count, record_counter, record_handle }; (*sdp_query_callback)((sdp_query_event_t*)&service_record_handle_event); } }
void handle_set_watch_config(ui_config* new_config) { //TODO: help check this ui_config* config = window_readconfig(); if (config != NULL) { memcpy(config, new_config, sizeof(ui_config)); //adjust values: big endian to little endian uint8_t* p = (uint8_t*)new_config; config->signature = READ_NET_32(p, 0); config->goal_steps = READ_NET_16(p, 4); config->goal_distance = READ_NET_16(p, 6); config->goal_calories = READ_NET_16(p, 8); config->lap_length = READ_NET_16(p, 10); if (config->weight < 20) config->weight = 20; if (config->height < 60) config->height = 60; log_info("set_watch_config:\n"); log_info(" signature = %x\n", config->signature); log_info(" default_clock = %d\n", config->default_clock); // 0 - analog, 1 - digit log_info(" analog_clock = %d\n", config->analog_clock); // num : which lock face log_info(" digit_clock = %d\n", config->digit_clock); // num : which clock face log_info(" sports_grid = %d\n", config->sports_grid); // 0 - 3 grid, 1 - 4 grid, 2 - 5 grid log_info(" sports_grids = %d, %d, %d, %d, %d\n", config->sports_grid_data[0], config->sports_grid_data[1], config->sports_grid_data[2], config->sports_grid_data[3], config->sports_grid_data[4]); log_info(" is_ukuint = %02x\n", config->is_ukuint); log_info(" goal_steps = %d\n", config->goal_steps); log_info(" goal_distance = %d\n", config->goal_distance); log_info(" goal_calories = %d\n", config->goal_calories); log_info(" weight = %d\n", config->weight); // in kg log_info(" height = %d\n", config->height); // in cm log_info(" circumference = %d\n", config->circumference); log_info(" lap_len = %d\n", config->lap_length); window_writeconfig(); window_loadconfig(); } }
int sdp_handle_service_attribute_request(uint8_t * packet, uint16_t remote_mtu) { // get request details uint16_t transaction_id = READ_NET_16(packet, 1); // not used yet - uint16_t param_len = READ_NET_16(packet, 3); uint32_t serviceRecordHandle = READ_NET_32(packet, 5); uint16_t maximumAttributeByteCount = READ_NET_16(packet, 9); uint8_t * attributeIDList = &packet[11]; uint16_t attributeIDListLen = de_get_len(attributeIDList); uint8_t * continuationState = &packet[11+attributeIDListLen]; // calc maximumAttributeByteCount based on remote MTU uint16_t maximumAttributeByteCount2 = remote_mtu - (7+3); if (maximumAttributeByteCount2 < maximumAttributeByteCount) { maximumAttributeByteCount = maximumAttributeByteCount2; } // continuation state contains the offset into the complete response uint16_t continuation_offset = 0; if (continuationState[0] == 2) { continuation_offset = READ_NET_16(continuationState, 1); } // get service record service_record_item_t * item = sdp_get_record_for_handle(serviceRecordHandle); if (!item) { // service record handle doesn't exist return sdp_create_error_response(transaction_id, 0x0002); /// invalid Service Record Handle } // AttributeList - starts at offset 7 uint16_t pos = 7; if (continuation_offset == 0) { // get size of this record uint16_t filtered_attributes_size = spd_get_filtered_size(item->service_record, attributeIDList); // store DES de_store_descriptor_with_len(&sdp_response_buffer[pos], DE_DES, DE_SIZE_VAR_16, filtered_attributes_size); maximumAttributeByteCount -= 3; pos += 3; } // copy maximumAttributeByteCount from record uint16_t bytes_used; int complete = sdp_filter_attributes_in_attributeIDList(item->service_record, attributeIDList, continuation_offset, maximumAttributeByteCount, &bytes_used, &sdp_response_buffer[pos]); pos += bytes_used; uint16_t attributeListByteCount = pos - 7; if (complete) { sdp_response_buffer[pos++] = 0; } else { continuation_offset += bytes_used; sdp_response_buffer[pos++] = 2; net_store_16(sdp_response_buffer, pos, continuation_offset); pos += 2; } // header sdp_response_buffer[0] = SDP_ServiceAttributeResponse; net_store_16(sdp_response_buffer, 1, transaction_id); net_store_16(sdp_response_buffer, 3, pos - 5); // size of variable payload net_store_16(sdp_response_buffer, 5, attributeListByteCount); return pos; }