/********************************** (C) COPYRIGHT *******************************
* File Name          : multiCentral.h
* Author             : WCH
* Version            : V1.0
* Date               : 2018/11/12
* Description        : 
*******************************************************************************/

#ifndef MULTICENTRAL_H
#define MULTICENTRAL_H
#include "gattprofile.h"
#ifdef __cplusplus
extern "C"
{
#endif

/*********************************************************************
 * INCLUDES
 */
#define PERIPHERAL_DEVICE_MAX_NUM         30
/*********************************************************************
 * CONSTANTS
 */

// Simple BLE Observer Task Events
#define START_DEVICE_EVT                              0x0001
#define START_DISCOVERY_EVT                           0x0002
#define START_SCAN_EVT                                0x0004
#define START_SVC_DISCOVERY_EVT                       0x0008
#define START_PARAM_UPDATE_EVT                        0x0010
#define START_READ_OR_WRITE_EVT                       0x0020
#define START_READ_RSSI_EVT                           0x0040
#define ESTABLISH_LINK_TIMEOUT_EVT                    0x0080

#define CONNECT0_ITEM                                 0
#define CONNECT1_ITEM                                 1
#define CONNECT2_ITEM                                 2

/*********************************************************************
 * MACROS
 */
 
 #define CENTRAL_CONNECTING     1     //主机正在连接
 #define CENTRAL_IDLE           0     //主机空闲
 
typedef struct
{
  uint8  taskID;                // Task ID for internal task/event processing
  uint16  connHandle;           // Connection handle of current connection
  uint8  state;                 // Application state
	//uint8  connecting;            //正在连接标志
  uint8  peerAddr[B_ADDR_LEN];
  uint8  discState;             // Discovery state
  uint8  procedureInProgress;   // GATT read/write procedure state
  uint16  svcStartHdl;          // Discovered service start handle
  uint16  svcEndHdl;            // Discovered service end handle
  uint16  charHdl;              // Discovered characteristic handle
} centralConnItem_t;

typedef struct
{
  uint8  peerAddr[B_ADDR_LEN];
} peerAddrDefItem_t;

extern BLE_DEVICE_CONFIG*  Ble_Device_Head;

/*********************************************************************
 * FUNCTIONS
 */

/*
 * Task Initialization for the BLE Application
 */
extern void Central_Init( void );

/*
 * Task Event Processor for the BLE Application
 */
extern uint16 Central_ProcessEvent( uint8 task_id, uint16 events );

void Clear_Connecting_flg(u8* addr);
void Set_Connecting_flg(u8* addr);

void BLE_Send_Task(void);
void Device_Add_List(BLE_DEVICE_CONFIG*  Device_node);                    //将设备添加进链表
uint8 IS_Empty_Connection(u8 device_type, u8 device_addr);                //查询指定设备是否已连接  
uint8 Connect_Peripheral_Device(u8 device_type, u8 device_addr);          //连接指定设备
uint8 Disconnect_Peripheral_Device(u8 device_type, u8 device_addr);       //断开指定设备
void Peripheral_Notify_Control(u8 device_type, u8 device_addr, u8 notify_id, u8 state); //打开或关闭指定从机设备的通知
/*********************************************************************
*********************************************************************/

#ifdef __cplusplus
}
#endif

#endif /* MULTICENTRAL_H */
