/**
 * @file ble_spp_server.h
 * @author LokLiang
 * @brief BLE 从机接口（服务端）
 * @version 0.1
 * @date 2023-11-01
 *
 * @copyright Copyright (c) 2023
 *
 */

#pragma once

#include "drivers/data_port/sb_data_port.h"
#include "os/os.h"

typedef enum
{
    BLE_SERVER_STATUS_STOP,
    BLE_SERVER_STATUS_CONNECTED,
    BLE_SERVER_STATUS_DISCONNECTED,
} ble_server_status_t;

typedef void (*ble_server_gen_manufacturer_data_cb)(uint8_t manufacturer_data[20]);
typedef void (*ble_server_connect_cb)(ble_server_status_t);

typedef struct
{
    const char *device_name;                               // 设备名
    ble_server_gen_manufacturer_data_cb manufacturer_data; // 回调函数，生成 manufacturer[20]
    ble_server_connect_cb connect_cb;                      // 回调函数， NULL 值可用
} ble_server_init_t;

typedef struct
{
    uint32_t buffer_size;     // 指定接收缓存长度
    os_work_t *wkup_work_hdl; // 当接收非空时唤醒的工作项， NULL 值可用
} ble_server_param_t;

int sb_ble_server_port_init(ble_server_init_t *init_param);

sb_data_port_t *ble_server_port_bind_cmd(uint32_t buffer_size, os_work_t *wkup_work_hdl);
sb_data_port_t *ble_server_port_bind_val(uint32_t buffer_size, os_work_t *wkup_work_hdl);
void ble_server_port_unbind_cmd(sb_data_port_t *port);
void ble_server_port_unbind_val(sb_data_port_t *port);

ble_server_status_t ble_server_get_gap_status(void);
uint32_t ble_server_get_mtu(void);

const uint8_t *ble_server_get_mac(void);
void ble_server_get_remote_mac(uint8_t *mac);
