/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ #include #include #include #include "host/ble_hs.h" #include "host/ble_uuid.h" #include "blecent.h" /** * Utility function to log an array of bytes. */ void print_bytes(const uint8_t *bytes, int len) { int i; for (i = 0; i < len; i++) { printf("%s0x%02x", i != 0 ? ":" : "", bytes[i]); } } void print_mbuf(const struct os_mbuf *om) { int colon; colon = 0; while (om != NULL) { if (colon) { printf(":"); } else { colon = 1; } print_bytes(om->om_data, om->om_len); om = SLIST_NEXT(om, om_next); } } char * addr_str(const void *addr) { static char buf[6 * 2 + 5 + 1]; const uint8_t *u8p; u8p = addr; sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x", u8p[5], u8p[4], u8p[3], u8p[2], u8p[1], u8p[0]); return buf; } void print_uuid(const ble_uuid_t *uuid) { char buf[BLE_UUID_STR_LEN]; printf("%s", ble_uuid_to_str(uuid, buf)); } /** * Logs information about a connection to the console. */ void print_conn_desc(const struct ble_gap_conn_desc *desc) { printf("handle=%d our_ota_addr_type=%d our_ota_addr=%s ", desc->conn_handle, desc->our_ota_addr.type, addr_str(desc->our_ota_addr.val)); printf("our_id_addr_type=%d our_id_addr=%s ", desc->our_id_addr.type, addr_str(desc->our_id_addr.val)); printf("peer_ota_addr_type=%d peer_ota_addr=%s ", desc->peer_ota_addr.type, addr_str(desc->peer_ota_addr.val)); printf("peer_id_addr_type=%d peer_id_addr=%s ", desc->peer_id_addr.type, addr_str(desc->peer_id_addr.val)); printf("conn_itvl=%d conn_latency=%d supervision_timeout=%d " "encrypted=%d authenticated=%d bonded=%d", desc->conn_itvl, desc->conn_latency, desc->supervision_timeout, desc->sec_state.encrypted, desc->sec_state.authenticated, desc->sec_state.bonded); } struct queue //½á¹¹ÌåÀàÐÍ { uint8_t totalnum;//»ùÕ¾×ÜÊý uint8_t flag_newanchor[anchor_max_num];//ÐÂÀÏ»ùÕ¾±íʾ uint16_t id[anchor_max_num]; /*ID*/ uint16_t time[anchor_max_num]; /*ʱ¼ä*/ uint16_t fail_num[anchor_max_num]; //uwb½ÓÊÜʧ°ÜµÄ´ÎÊý uint16_t rssi[anchor_max_num];//À¶ÑÀ²â³öµÄ¾àÀë uint8_t uwb_tongxun_flag[anchor_max_num];//ÓëuwbͨѶ³É¹¦Ê§°ÜµÄ±ê־λ uint16_t u16id[anchor_max_num]; /*u16ID*/ }blequeue; static char ble_anchor_name[20]="HFGD_XB"; uint16_t u16ble_id_fen[30]; uint8_t u16ble_id_fen1[50]; uint16_t rssidata; uint8_t a; void print_adv_fields(const struct ble_hs_adv_fields *fields,const struct ble_gap_disc_desc *disc) { char s[BLE_HS_ADV_MAX_SZ]; char mac[100]; const uint8_t *u8p; int i; uint16_t ble_id=0; uint16_t rssi=0; uint8_t repeat_flag=0; uint8_t ble_id_fen[2]; if (fields->name != NULL) { assert(fields->name_len < sizeof s - 1); memcpy(s, fields->name, fields->name_len); if(!memcmp(s,ble_anchor_name,fields->name_len)) { // memcpy(mac, fields->public_tgt_addr, fields->num_public_tgt_addrs); // s[fields->name_len] = '\0'; // printf(" name(complete)=%s\n", // s); /*²âÊÔģʽ rssidata=rssidata+abs(disc->rssi); a++; if(a==10) { printf(" name(complete)=%s\n", s); printf("RSSI:%d\r\n",rssidata/10); a=0; rssidata=0; } */ // printf("\n"); // uart_data_send(&UART0_OBJ, mac,fields->num_public_tgt_addrs); // printf("\n"); // memset(mac,0,100); // ble_id_fen[0]=fields->svc_data_uuid16[1]; // ble_id_fen[1]=fields->svc_data_uuid16[0]; // u16ble_id_fen[0]=fields->svc_data_uuid16[1]; // u16ble_id_fen[1]=fields->svc_data_uuid16[0]; memcpy(&ble_id,&disc->addr.val[0],2);//´ÓɨÃèµÄÊý¾ÝÖÐÄóöid rssi=abs(disc->rssi); for(i=0;i