是否可以在自定义GATT服务中创建四个特征?

时间:2019-05-06 08:42:04

标签: movesense

我正在使用custom_gattsvc_app示例应用程序作为起点在Movesense传感器上设置自定义GATT服务。在原始示例应用程序中创建了两个特征,但是当我尝试使用相同的语法添加两个特征时,最终只能创建其中一个。 This presentation指出最多可以创建四个特征,所以我想我一定做错了。我的代码是这样设置的:

在CustomGATTSvcClient.h文件中:

whiteboard::ResourceId mIntervalCharResource;
whiteboard::ResourceId mMeasCharResource;
whiteboard::ResourceId mAlphaCharResource;
whiteboard::ResourceId mBetaCharResource;

uint16_t mMeasIntervalSecs;
uint16_t mAlphaValue;
uint16_t mBetaValue;
int32_t mTemperatureSvcHandle;
int32_t mMeasCharHandle;
int32_t mIntervalCharHandle;
int32_t mAlphaCharHandle;
int32_t mBetaCharHandle;

在CustomGATTSvcClient.cpp文件中:

const uint16_t measCharUUID16 = 0x2A1C;
const uint16_t intervalCharUUID16 = 0x2A21;
const uint16_t alphaCharUUID16 = 0x2A1F;
const uint16_t betaCharUUID16 = 0x2A2E;

const int DEFAULT_MEASUREMENT_INTERVAL_SECS = 1;
const int DEFAULT_ALPHA_VALUE = 1;
const int DEFAULT_BETA_VALUE = 1;
CustomGATTSvcClient::CustomGATTSvcClient()
    : ResourceClient(WBDEBUG_NAME(__FUNCTION__), WB_EXEC_CTX_APPLICATION),
    LaunchableModule(LAUNCHABLE_NAME, WB_EXEC_CTX_APPLICATION),
    mMeasIntervalSecs(DEFAULT_MEASUREMENT_INTERVAL_SECS),
    mAlphaValue(DEFAULT_ALPHA_VALUE),
    mBetaValue(DEFAULT_BETA_VALUE),
    mTemperatureSvcHandle(0),
    mMeasCharHandle(0),
    mIntervalCharHandle(0),
    mAlphaCharHandle(0),
    mBetaCharHandle(0),
    mIntervalCharResource(whiteboard::ID_INVALID_RESOURCE),
    mMeasCharResource(whiteboard::ID_INVALID_RESOURCE),
    mAlphaCharResource(whiteboard::ID_INVALID_RESOURCE),
    mBetaCharResource(whiteboard::ID_INVALID_RESOURCE),
{
}
void CustomGATTSvcClient::configGattSvc() {
  WB_RES::GattSvc customGattSvc;
  WB_RES::GattChar characteristics[4];
  WB_RES::GattChar &measChar = characteristics[0];
  WB_RES::GattChar &intervalChar = characteristics[1];
  WB_RES::GattChar &alphaChar = characteristics[2];
  WB_RES::GattChar &betaChar = characteristics[3];

  const uint16_t healthThermometerSvcUUID16 = 0x1809;

  WB_RES::GattProperty measCharProp[3] = {WB_RES::GattProperty::NOTIFY, WB_RES::GattProperty::READ};
  WB_RES::GattProperty intervalCharProps[2] = {WB_RES::GattProperty::READ, WB_RES::GattProperty::WRITE};
  WB_RES::GattProperty alphaCharProps[2] = {WB_RES::GattProperty::READ, WB_RES::GattProperty::WRITE};
  WB_RES::GattProperty betaCharProps[2] = {WB_RES::GattProperty::READ, WB_RES::GattProperty::WRITE};

  measChar.props = whiteboard::MakeArray<WB_RES::GattProperty>( measCharProp, 3);
  measChar.uuid = whiteboard::MakeArray<uint8_t>( reinterpret_cast<const uint8_t*>(&measCharUUID16), 2);

  intervalChar.props = whiteboard::MakeArray<WB_RES::GattProperty>( intervalCharProps, 2);
  intervalChar.uuid = whiteboard::MakeArray<uint8_t>( reinterpret_cast<const uint8_t*>(&intervalCharUUID16), 2);
  intervalChar.initial_value = whiteboard::MakeArray<uint8_t>( reinterpret_cast<const uint8_t*>(&mMeasIntervalSecs), 2);

  alphaChar.props = whiteboard::MakeArray<WB_RES::GattProperty>( alphaCharProps, 2);
  alphaChar.uuid = whiteboard::MakeArray<uint8_t>( reinterpret_cast<const uint8_t*>(&alphaCharUUID16), 2);
  alphaChar.initial_value = whiteboard::MakeArray<uint8_t>( reinterpret_cast<const uint8_t*>(&mAlphaValue), 2);

  betaChar.props = whiteboard::MakeArray<WB_RES::GattProperty>( betaCharProps, 2);
  betaChar.uuid = whiteboard::MakeArray<uint8_t>( reinterpret_cast<const uint8_t*>(&betaCharUUID16), 2);
  betaChar.initial_value = whiteboard::MakeArray<uint8_t>( reinterpret_cast<const uint8_t*>(&mBetaValue), 2);

  // Combine chars to service
  customGattSvc.uuid = whiteboard::MakeArray<uint8_t>( reinterpret_cast<const uint8_t*>(&healthThermometerSvcUUID16), 2);
  customGattSvc.chars = whiteboard::MakeArray<WB_RES::GattChar>(characteristics, 4);

  // Create custom service
  asyncPost(WB_RES::LOCAL::COMM_BLE_GATTSVC(), AsyncRequestOptions::Empty, customGattSvc);
}

0 个答案:

没有答案