WXK
2025-01-21 8f1a91a8ec98e430cfe4357bda099d495917198e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
 *******************************************************************************
 * @file     app_ble.c
 * @create   2023-08-01    
 * @author   Panchip BLE GROUP
 * @note
 * Copyright (c) 2022 Shanghai Panchip Microelectronics Co.,Ltd.
 *
 *******************************************************************************
 */
#include <assert.h>
#include <string.h>
 
#include "pan_ble.h"
#include "app.h"
#include "app_log.h"
 
static void app_ble_set_mac_addr(void)
{
    /** set public address*/
    uint8_t pub_mac[6]={8,2,3,4,5,6};
    
#if CONFIG_USER_CHIP_MAC_ADDR
    pan10x_mac_addr_get(pub_mac);
#endif
    
#if APP_USER_ROLL_MAC_ADDR
    pan10x_roll_mac_addr_get(pub_mac);
#endif
    
    pan_misc_set_bd_addr(pub_mac);
}
 
/**
 * @brief: BLE Stack Enabled call-back.
 */
static void app_ble_enabled_cb(void)
{
#if CONFIG_BT_MAX_NUM_OF_PERIPHERAL
    /* Adv */
    app_ble_adv_start();
#endif
 
#if CONFIG_BT_MAX_NUM_OF_CENTRAL 
    /* Scan */
    app_ble_scan_start();
#endif
}
 
/**
 * @brief: ble stack pre init call-back
 *         !!!Note: 1. The Bluetooth MAC Address must be set in this callback.
 *                  2. The BLE Services must be registered in this callback.
 *                  3. The SDP initialization must be executed in this callback.
 */
TimerHandle_t xTimerUser; 
uint16_t timer;
extern 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;
uint8_t slave_send_buf[100];
void Spi_Zubao_Send(void)
{   
    if(blequeue.totalnum>10)
    {blequeue.totalnum=10;}
    memset(slave_send_buf,0,sizeof(slave_send_buf));
    slave_send_buf[0]=0X55;
    slave_send_buf[1]=0XAA;
    slave_send_buf[2]=blequeue.totalnum*4+2;
    slave_send_buf[3]=blequeue.totalnum;
    memcpy(&slave_send_buf[4],blequeue.id,2*blequeue.totalnum);
    memcpy(&slave_send_buf[4+2*blequeue.totalnum],blequeue.rssi,2*blequeue.totalnum);
    slave_send_buf[4+4*blequeue.totalnum]=0x66;
    slave_send_buf[5+4*blequeue.totalnum]=0xBB;
    HAL_UART_SendData(&UART0_OBJ, slave_send_buf,blequeue.totalnum*4+6,1000);
    blequeue.totalnum=0;
 
    memset(blequeue.id,0,sizeof(blequeue.id));
    memset(blequeue.u16id,0,sizeof(blequeue.u16id));
    memset(blequeue.rssi,0,sizeof(blequeue.rssi));
}
void vTimerCallback( TimerHandle_t xTimer )
{    
timer++;
    Spi_Zubao_Send();
}
void app_ble_pre_init_cb(void)
{
    /* Set MAC address. */
    app_ble_set_mac_addr();
 
    /* BLE Peripheral initilaization. */
    app_ble_periph_init();
 
    /* BLE Central initilaization. */
    app_ble_central_init();
    
    /* BLE Services initilaization. */
    app_ble_svc_init();
    
    img_mgmt_module_init();
    smp_ble_pkg_init();
    
    xTimerUser = xTimerCreate("Timer's name",pdMS_TO_TICKS(900),pdTRUE,( void * ) 0,vTimerCallback);                 
    if( xTimerUser != NULL ) {
    xTimerStart( xTimerUser, 0 );
    }
}
 
void app_ble_init(void)
{
    /* BLE Stack Initialization. */
    pan_ble_stack_init(app_ble_pre_init_cb, app_ble_enabled_cb);
}