Skip to content

Commit

Permalink
Use Uint8:: helpers instead of reinterpret_cast
Browse files Browse the repository at this point in the history
  • Loading branch information
arkq committed Mar 21, 2023
1 parent 932a121 commit 894335c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/platform/Tizen/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <ble/Ble.h>
#include <ble/CHIPBleServiceData.h>
#include <lib/core/CHIPError.h>
#include <lib/core/CHIPSafeCasts.h>
#include <lib/support/BitFlags.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/ErrorStr.h>
Expand Down Expand Up @@ -188,7 +189,7 @@ void BLEManagerImpl::ReadValueRequestedCb(const char * remoteAddress, int reques
ret = bt_gatt_get_value(gattHandle, &value, &len);
VerifyOrReturn(ret == BT_ERROR_NONE, ChipLogError(DeviceLayer, "bt_gatt_get_value() failed. ret: %d", ret));

ChipLogByteSpan(DeviceLayer, ByteSpan(reinterpret_cast<const uint8_t *>(value), len));
ChipLogByteSpan(DeviceLayer, ByteSpan(Uint8::from_const_char(value), len));

ret = bt_gatt_server_send_response(requestId, BT_GATT_REQUEST_TYPE_READ, offset, 0x00, value, len);
g_free(value);
Expand All @@ -210,7 +211,7 @@ void BLEManagerImpl::WriteValueRequestedCb(const char * remoteAddress, int reque
ChipLogError(DeviceLayer, "Failed to fetch GATT Attribute from GATT handle"));
ChipLogProgress(DeviceLayer, "Gatt write requested on %s: uuid=%s len=%d", __ConvertAttTypeToStr(type),
StringOrNullMarker(uuid), len);
ChipLogByteSpan(DeviceLayer, ByteSpan(reinterpret_cast<const uint8_t *>(value), len));
ChipLogByteSpan(DeviceLayer, ByteSpan(Uint8::from_const_char(value), len));
g_free(uuid);

ret = bt_gatt_set_value(gattHandle, value, len);
Expand All @@ -219,7 +220,7 @@ void BLEManagerImpl::WriteValueRequestedCb(const char * remoteAddress, int reque
ret = bt_gatt_server_send_response(requestId, BT_GATT_REQUEST_TYPE_WRITE, offset, 0x00, nullptr, 0);
VerifyOrReturn(ret == BT_ERROR_NONE, ChipLogError(DeviceLayer, "bt_gatt_server_send_response() failed. ret: %d", ret));

sInstance.HandleC1CharWriteEvent(conn, reinterpret_cast<const uint8_t *>(value), len);
sInstance.HandleC1CharWriteEvent(conn, Uint8::from_const_char(value), len);
}

void BLEManagerImpl::NotificationStateChangedCb(bool notify, bt_gatt_server_h server, bt_gatt_h gattHandle, void * userData)
Expand Down Expand Up @@ -270,7 +271,7 @@ void BLEManagerImpl::CharacteristicNotificationCb(bt_gatt_h characteristic, char
VerifyOrReturn(conn->gattCharC2Handle == characteristic, ChipLogError(DeviceLayer, "Gatt characteristic handle did not match"));

ChipLogProgress(DeviceLayer, "Notification Received from CHIP peripheral [%s]", conn->peerAddr);
sInstance.HandleRXCharChanged(conn, reinterpret_cast<const uint8_t *>(value), len);
sInstance.HandleRXCharChanged(conn, Uint8::from_const_char(value), len);
}

void BLEManagerImpl::IndicationConfirmationCb(int result, const char * remoteAddress, bt_gatt_server_h server,
Expand Down Expand Up @@ -1279,7 +1280,7 @@ bool BLEManagerImpl::SendIndication(BLE_CONNECTION_OBJECT conId, const Ble::Chip
conn = static_cast<BLEConnection *>(g_hash_table_lookup(sInstance.mConnectionMap, conn->peerAddr));
VerifyOrExit(conn != nullptr, ChipLogError(DeviceLayer, "Failed to find connection info"));

ret = bt_gatt_set_value(mGattCharC2Handle, reinterpret_cast<const char *>(pBuf->Start()), pBuf->DataLength());
ret = bt_gatt_set_value(mGattCharC2Handle, Uint8::to_const_char(pBuf->Start()), pBuf->DataLength());
VerifyOrExit(ret == BT_ERROR_NONE, ChipLogError(DeviceLayer, "bt_gatt_set_value() failed. ret: %d", ret));

ChipLogProgress(DeviceLayer, "Sending indication for CHIPoBLE RX characteristic (con %s, len %u)", conn->peerAddr,
Expand Down Expand Up @@ -1314,7 +1315,7 @@ bool BLEManagerImpl::SendWriteRequest(BLE_CONNECTION_OBJECT conId, const Ble::Ch
ChipLogError(DeviceLayer, "SendWriteRequest() called with invalid characteristic ID"));
VerifyOrExit(conn->gattCharC1Handle != nullptr, ChipLogError(DeviceLayer, "Char C1 is null"));

ret = bt_gatt_set_value(conn->gattCharC1Handle, reinterpret_cast<const char *>(pBuf->Start()), pBuf->DataLength());
ret = bt_gatt_set_value(conn->gattCharC1Handle, Uint8::to_const_char(pBuf->Start()), pBuf->DataLength());
VerifyOrExit(ret == BT_ERROR_NONE, ChipLogError(DeviceLayer, "bt_gatt_set_value() failed. ret: %d", ret));

ChipLogProgress(DeviceLayer, "Sending Write Request for CHIPoBLE TX characteristic (con %s, len %u)", conn->peerAddr,
Expand Down

0 comments on commit 894335c

Please sign in to comment.