mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2024-11-27 10:50:41 +00:00
fix : gatt client writeType can be setted
Signed-off-by: wangjingen <wangjingen1@huawei.com>
This commit is contained in:
parent
24852f934e
commit
c863a90216
@ -406,19 +406,36 @@ int32_t SoftbusGattcConfigureMtuSize(int32_t clientId, int mtuSize)
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static BtGattWriteType ConvertBtWriteType(SoftBusGattWriteType writeType)
|
||||
{
|
||||
switch (writeType) {
|
||||
case SOFTBUS_GATT_WRITE_NO_RSP:
|
||||
return OHOS_GATT_WRITE_NO_RSP;
|
||||
case SOFTBUS_GATT_WRITE_DEFAULT:
|
||||
return OHOS_GATT_WRITE_DEFAULT;
|
||||
case SOFTBUS_GATT_WRITE_PREPARE:
|
||||
return OHOS_GATT_WRITE_PREPARE;
|
||||
case SOFTBUS_GATT_WRITE_SIGNED:
|
||||
return OHOS_GATT_WRITE_SIGNED;
|
||||
default:
|
||||
return OHOS_GATT_WRITE_TYPE_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t SoftbusGattcWriteCharacteristic(int32_t clientId, SoftBusGattcData *clientData)
|
||||
{
|
||||
if (clientId <= 0 || clientData == NULL) {
|
||||
CONN_LOGE(CONN_BLE, "invalid param");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
CONN_LOGI(CONN_BLE, "clientId = %{public}d", clientId);
|
||||
CONN_LOGI(CONN_BLE, "clientId = %{public}d, writeType=%{public}d", clientId, clientData->writeType);
|
||||
BtGattCharacteristic characteristic;
|
||||
characteristic.serviceUuid.uuid = clientData->serviceUuid.uuid;
|
||||
characteristic.serviceUuid.uuidLen = clientData->serviceUuid.uuidLen;
|
||||
characteristic.characteristicUuid.uuid = clientData->characterUuid.uuid;
|
||||
characteristic.characteristicUuid.uuidLen = clientData->characterUuid.uuidLen;
|
||||
if (BleGattcWriteCharacteristic(clientId, characteristic, OHOS_GATT_WRITE_NO_RSP, clientData->valueLen,
|
||||
BtGattWriteType writeType = ConvertBtWriteType(clientData->writeType);
|
||||
if (BleGattcWriteCharacteristic(clientId, characteristic, writeType, clientData->valueLen,
|
||||
(const char *)clientData->value) != SOFTBUS_OK) {
|
||||
CONN_LOGE(CONN_BLE, "error");
|
||||
return SOFTBUS_GATTC_INTERFACE_FAILED;
|
||||
|
@ -34,11 +34,20 @@ typedef struct {
|
||||
uint8_t *data;
|
||||
} SoftBusGattcNotify;
|
||||
|
||||
typedef enum {
|
||||
SOFTBUS_GATT_WRITE_NO_RSP = 0x1,
|
||||
SOFTBUS_GATT_WRITE_DEFAULT,
|
||||
SOFTBUS_GATT_WRITE_PREPARE,
|
||||
SOFTBUS_GATT_WRITE_SIGNED,
|
||||
SOFTBUS_GATT_WRITE_TYPE_UNKNOWN,
|
||||
} SoftBusGattWriteType;
|
||||
|
||||
typedef struct {
|
||||
SoftBusBtUuid serviceUuid;
|
||||
SoftBusBtUuid characterUuid;
|
||||
uint32_t valueLen;
|
||||
const uint8_t *value;
|
||||
SoftBusGattWriteType writeType;
|
||||
} SoftBusGattcData;
|
||||
|
||||
typedef struct {
|
||||
|
@ -804,6 +804,7 @@ int32_t ConnGattClientSend(ConnBleConnection *connection, const uint8_t *data, u
|
||||
},
|
||||
.value = data,
|
||||
.valueLen = dataLen,
|
||||
.writeType = SOFTBUS_GATT_WRITE_NO_RSP,
|
||||
};
|
||||
return SoftbusGattcWriteCharacteristic(underlayerHandle, &gattcData);
|
||||
}
|
||||
|
@ -270,6 +270,18 @@ HWTEST_F(AdapterBleGattClientTest, SoftbusGattcWriteCharacteristic, TestSize.Lev
|
||||
|
||||
EXPECT_CALL(mocker, BleGattcWriteCharacteristic).WillRepeatedly(Return(OHOS_BT_STATUS_SUCCESS));
|
||||
EXPECT_EQ(SoftbusGattcWriteCharacteristic(1, &data), SOFTBUS_OK);
|
||||
|
||||
data.writeType = SOFTBUS_GATT_WRITE_NO_RSP;
|
||||
EXPECT_EQ(SoftbusGattcWriteCharacteristic(1, &data), SOFTBUS_OK);
|
||||
|
||||
data.writeType = SOFTBUS_GATT_WRITE_PREPARE;
|
||||
EXPECT_EQ(SoftbusGattcWriteCharacteristic(1, &data), SOFTBUS_OK);
|
||||
|
||||
data.writeType = SOFTBUS_GATT_WRITE_DEFAULT;
|
||||
EXPECT_EQ(SoftbusGattcWriteCharacteristic(1, &data), SOFTBUS_OK);
|
||||
|
||||
data.writeType = SOFTBUS_GATT_WRITE_SIGNED;
|
||||
EXPECT_EQ(SoftbusGattcWriteCharacteristic(1, &data), SOFTBUS_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user