/*---------------------------------------------------------------------------- * Copyright (c) Fenda Technologies Co., Ltd. 2022. All rights reserved. * * Description: 汇顶APP服务 * * Author: george * * Create: 2022-11-10 *--------------------------------------------------------------------------*/ #include "svc_gdcs.h" #include "wsf_types.h" #include "bstream.h" #include "att_defs.h" #include "att_uuid.h" /******************************************************************************/ /* Macro definitions */ /******************************************************************************/ /* Base UUID: XXXXXXXX-0000-1000-8000-00805f9b34fb */ #define GDCS_UUID_BASE 0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, \ 0x00, 0x80, 0x00, 0x10, 0x00, 0x00 /* Macro for building UUIDs */ #define GDCS_UUID_BUILD(part) GDCS_UUID_BASE, UINT32_TO_BYTES(part) /* Partial UUIDs of the service. */ #define GDCS_SERVICE_UUID_PART 0x0000190E /* Partial GDCS rx characteristic UUIDs */ #define GDCS_RX_CH_UUID_PART 0x00000004 /* Partial GDCS tx characteristic UUIDs */ #define GDCS_TX_CH_UUID_PART 0x00000003 /* GDCS services UUID */ #define GDCS_SERVICE_UUID GDCS_UUID_BUILD(GDCS_SERVICE_UUID_PART) /* GDCS characteristics */ #define GDCS_RX_CH_UUID GDCS_UUID_BUILD(GDCS_RX_CH_UUID_PART) #define GDCS_TX_CH_UUID GDCS_UUID_BUILD(GDCS_TX_CH_UUID_PART) /******************************************************************************/ /* Static Variables */ /******************************************************************************/ static const uint8_t svcRxUuid[] = {GDCS_RX_CH_UUID}; static const uint8_t svcTxUuid[] = {GDCS_TX_CH_UUID}; /******************************************************************************/ /* Service variables */ /******************************************************************************/ /* GDCS service declaration */ static const uint8_t GdcsSvc[] = {GDCS_SERVICE_UUID}; static const uint16_t GdcsLenSvc = sizeof(GdcsSvc); /* GDCS RX characteristic */ static const uint8_t GdcsRxCh[] = { ATT_PROP_WRITE_NO_RSP, UINT16_TO_BYTES(GDCS_RX_HDL), GDCS_RX_CH_UUID }; static const uint16_t GdcsLenRxCh = sizeof(GdcsRxCh); /* GDCS RX data */ static const uint8_t GdcsRx[] = {0}; static const uint16_t GdcsLenRx = sizeof(GdcsRx); /* GDCS TX characteristic */ static const uint8_t GdcsTxCh[] = { ATT_PROP_NOTIFY, UINT16_TO_BYTES(GDCS_TX_HDL), GDCS_TX_CH_UUID }; static const uint16_t GdcsLenTxCh = sizeof(GdcsTxCh); /* GDCS TX data */ static const uint8_t GdcsTx[] = {0}; static const uint16_t GdcsLenTx = sizeof(GdcsTx); /* Proprietary data client characteristic configuration */ static uint8_t GdcsTxChCcc[] = {UINT16_TO_BYTES(0x0000)}; static const uint16_t GdcsLenTxChCcc = sizeof(GdcsTxChCcc); /* Attribute list for GDCS group */ static const attsAttr_t GdcsList[] = { /* Service declaration */ { attPrimSvcUuid, (uint8_t *) GdcsSvc, (uint16_t *) &GdcsLenSvc, sizeof(GdcsSvc), 0, ATTS_PERMIT_READ }, /* Characteristic declaration */ { attChUuid, (uint8_t *) GdcsRxCh, (uint16_t *) &GdcsLenRxCh, sizeof(GdcsRxCh), 0, ATTS_PERMIT_READ }, /* Characteristic value */ { svcRxUuid, (uint8_t *) GdcsRx, (uint16_t *) &GdcsLenRx, ATT_VALUE_MAX_LEN, (ATTS_SET_UUID_128 | ATTS_SET_VARIABLE_LEN | ATTS_SET_WRITE_CBACK), ATTS_PERMIT_WRITE }, /* Characteristic declaration */ { attChUuid, (uint8_t *) GdcsTxCh, (uint16_t *) &GdcsLenTxCh, sizeof(GdcsTxCh), 0, ATTS_PERMIT_READ }, /* Characteristic value */ { svcTxUuid, (uint8_t *) GdcsTx, (uint16_t *) &GdcsLenTx, ATT_VALUE_MAX_LEN, (ATTS_SET_UUID_128 | ATTS_SET_VARIABLE_LEN), ATTS_PERMIT_READ }, /* Characteristic CCC descriptor */ { attCliChCfgUuid, (uint8_t *) GdcsTxChCcc, (uint16_t *) &GdcsLenTxChCcc, sizeof(GdcsTxChCcc), ATTS_SET_CCC, (ATTS_PERMIT_READ | ATTS_PERMIT_WRITE) } }; /* GDCS group structure */ static attsGroup_t svcGdcsGroup = { NULL, (attsAttr_t *) GdcsList, NULL, NULL, GDCS_START_HDL, GDCS_END_HDL }; /** @brief Add the services to the attribute server. */ void svc_gdcs_add_group(void) { AttsAddGroup(&svcGdcsGroup); } /** @brief Remove the services from the attribute server. */ void svc_gdcs_remove_group(void) { AttsRemoveGroup(GDCS_START_HDL); } /** @brief Register callbacks for the service. */ void svc_gdcs_cback_register(attsReadCback_t readCback, attsWriteCback_t writeCback) { svcGdcsGroup.readCback = readCback; svcGdcsGroup.writeCback = writeCback; }