139 lines
3.8 KiB
C
139 lines
3.8 KiB
C
/*----------------------------------------------------------------------------
|
|
* Copyright (c) Fenda Technologies Co., Ltd. 2022. All rights reserved.
|
|
*
|
|
* Description: 汇顶APP服务
|
|
*
|
|
* Author: george
|
|
*
|
|
* Create: 2022-11-10
|
|
*--------------------------------------------------------------------------*/
|
|
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include "wsf_types.h"
|
|
#include "wsf_assert.h"
|
|
#include "wsf_trace.h"
|
|
#include "wsf_buf.h"
|
|
|
|
#include "am_util_debug.h"
|
|
#include "sys_config.h"
|
|
|
|
#include "svc_gdcs.h"
|
|
#include "ble_gdcs_api.h"
|
|
|
|
#include "gh3011_example_common.h"
|
|
|
|
#define ENABLE_STATIC_PRINT true
|
|
extern uint32_t am_util_stdio_printf(const char *pcFmt, ...);
|
|
#define static_print_remind(...) am_util_stdio_printf(__VA_ARGS__)
|
|
#if ENABLE_STATIC_PRINT
|
|
#define static_print_info(...) am_util_stdio_printf(__VA_ARGS__)
|
|
#else
|
|
#define static_print_info(...)
|
|
#endif
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
/* Type definitions */
|
|
/******************************************************************************/
|
|
/** @brief Connection control block */
|
|
typedef struct {
|
|
dmConnId_t connId; /*!< Connection ID */
|
|
bool_t toSend; /*!< Notify ready to be sent on this channel */
|
|
} GdcsConn_t;
|
|
|
|
/******************************************************************************/
|
|
/* Local Variables */
|
|
/******************************************************************************/
|
|
/** @brief Gdcs profile control block */
|
|
static struct {
|
|
GdcsConn_t conn[DM_CONN_MAX]; /*!< Connection control block */
|
|
wsfHandlerId_t handlerId; /*!< Gdcs service WSF handle ID */
|
|
GdcsCfg_t cfg; /*!< Configurable parameters */
|
|
|
|
bool_t txReady; // TRUE if ready to send notifications
|
|
} GdcsCb;
|
|
|
|
|
|
static GdcsConn_t* gdcs_find_next2send(void)
|
|
{
|
|
GdcsConn_t *pConn = GdcsCb.conn;
|
|
for(uint8_t i = 0; i < DM_CONN_MAX; i++, pConn++) {
|
|
if(pConn->connId != DM_CONN_ID_NONE) {
|
|
return pConn;
|
|
}
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
bool gdcs_get_notify_status(void)
|
|
{
|
|
GdcsConn_t *pConn = gdcs_find_next2send();
|
|
if(pConn)
|
|
{
|
|
return true;
|
|
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void gdcs_init(wsfHandlerId_t handlerId)
|
|
{
|
|
memset(&GdcsCb, 0, sizeof(GdcsCb));
|
|
GdcsCb.handlerId = handlerId;
|
|
|
|
GdcsCb.txReady = false;
|
|
for(int i = 0; i < DM_CONN_MAX; i++) {
|
|
GdcsCb.conn[i].connId = DM_CONN_ID_NONE;
|
|
}
|
|
}
|
|
|
|
void gdcs_start(dmConnId_t connId)
|
|
{
|
|
GdcsCb.conn[connId - 1].connId = connId;
|
|
GdcsCb.conn[connId - 1].toSend = true;
|
|
|
|
GdcsCb.txReady = true;
|
|
}
|
|
|
|
void gdcs_stop(dmConnId_t connId)
|
|
{
|
|
GdcsCb.conn[connId - 1].connId = DM_CONN_ID_NONE;
|
|
GdcsCb.conn[connId - 1].toSend = false;
|
|
|
|
GdcsCb.txReady = false;
|
|
}
|
|
|
|
void gdcs_send_data(uint8_t *buf, uint16_t len)
|
|
{
|
|
GdcsConn_t *pConn = gdcs_find_next2send();
|
|
if (pConn == NULL) {
|
|
static_print_info("gdcs Invalid Conn = %d\n", pConn->connId);
|
|
return;
|
|
}
|
|
|
|
AttsHandleValueNtf(pConn->connId, GDCS_TX_HDL, len, buf);
|
|
}
|
|
|
|
uint8_t gdcs_write_cback(dmConnId_t connId, uint16_t handle,
|
|
uint8_t operation, uint16_t offset,
|
|
uint16_t len, uint8_t *pValue, attsAttr_t *pAttr)
|
|
{
|
|
uint8_t err_code = 0;
|
|
|
|
#if 0
|
|
/* 输出打印接收的数据 */
|
|
static_print_info("GdcsWriteCback---START\n");
|
|
for(uint8_t i = 0; i < len; i++) {
|
|
static_print_info("%x ", pValue[i]);
|
|
}
|
|
static_print_info("\n");
|
|
#endif
|
|
ble_module_recv_data_via_gdcs(pValue, len);
|
|
|
|
return err_code;
|
|
}
|