#define CA_BLE_LENGTH_HEADER_SIZE 4
/**
+ * The length payload size of the normal data segment (after first segment) for ble fragmentation.
+ */
+#define CA_BLE_NORMAL_SEGMENT_PAYLOAD_SIZE CA_SUPPORTED_BLE_MTU_SIZE \
+ - CA_BLE_HEADER_SIZE
+
+/**
+ * The length payload size of the first data segment for ble fragmentation.
+ */
+#define CA_BLE_FIRST_SEGMENT_PAYLOAD_SIZE CA_BLE_NORMAL_SEGMENT_PAYLOAD_SIZE \
+ - CA_BLE_LENGTH_HEADER_SIZE
+
+/**
* Current Header version.
*/
#define HEADER_VERSION 1
* to maintain the fragmentation logic. start data segment is included
* 2 bytes header and transmit data.
*
- * @param[out] dataSegment Pointer to the octet array that will
- * contain the generated data packet.
- * @param[in] data Data to the octet array that required
- * transmittin to remote device. it will
- * be embedded in 7th byte to data length.
- * @param[in] dataLength The length of data size.
- * @param[in] index Index to determine whether some of the
- * total data
- * @param[in] dataHeader Pointer to the octet array that contain
- * data header.
+ * @param[out] dataSegment Pointer to the octet array that will
+ * contain the generated data packet.
+ * @param[in] segmentPayloadLength The length of data segment payload.
+ * @param[in] sourceData Data to the octet array that required
+ * transmission to remote device. it will
+ * be embedded in 7th byte to data length.
+ * @param[in] sourceDataLength The length of total data.
+ * @param[in] segmentNum Index to determine whether some of the
+ * total data
+ * @param[in] dataHeader Pointer to the octet array that contain
+ * data header.
*
* @return ::CA_STATUS_OK on success. One of the CA_STATUS_FAILED
* or other error values on error.
* @retval ::CA_STATUS_FAILED Operation failed
*/
CAResult_t CAMakeRemainDataSegment(uint8_t *dataSegment,
- const uint8_t *data,
- const uint32_t dataLength,
- const uint32_t index,
+ const uint32_t segmentPayloadLength,
+ const uint8_t *sourceData,
+ const uint32_t sourceDataLength,
+ const uint32_t segmentNum,
const uint8_t *dataHeader);
/**
}
CAResult_t CAMakeRemainDataSegment(uint8_t *dataSegment,
- const uint8_t *data,
- const uint32_t dataLength,
- const uint32_t index,
+ const uint32_t segmentPayloadLength,
+ const uint8_t *sourceData,
+ const uint32_t sourceDataLength,
+ const uint32_t segmentNum,
const uint8_t *dataHeader)
{
OIC_LOG(DEBUG, TAG, "IN");
VERIFY_NON_NULL(dataSegment, TAG, "dataSegment is NULL");
VERIFY_NON_NULL(dataHeader, TAG, "dataHeader is NULL");
- const uint8_t *cur_pos = data +
- (CA_SUPPORTED_BLE_MTU_SIZE - CA_BLE_HEADER_SIZE - CA_BLE_LENGTH_HEADER_SIZE +
- (index * (CA_SUPPORTED_BLE_MTU_SIZE - CA_BLE_HEADER_SIZE)));
- if (NULL == cur_pos)
+ uint32_t index = CA_BLE_FIRST_SEGMENT_PAYLOAD_SIZE +
+ (segmentNum * CA_BLE_NORMAL_SEGMENT_PAYLOAD_SIZE);
+ if (sourceDataLength < index + segmentPayloadLength)
{
- OIC_LOG(ERROR, TAG, "data is NULL");
+ OIC_LOG(DEBUG, TAG, "dataSegment will exceed");
return CA_STATUS_FAILED;
}
memcpy(dataSegment, dataHeader, CA_BLE_HEADER_SIZE);
- memcpy(dataSegment + CA_BLE_HEADER_SIZE, cur_pos, dataLength);
+ memcpy(dataSegment + CA_BLE_HEADER_SIZE, sourceData + index, segmentPayloadLength);
OIC_LOG(DEBUG, TAG, "OUT");
/**
* Stores information of all the senders.
*
- * This structure will be used to track and defragment all incoming
- * data packet.
+ * This structure will be used to track and defragment all incoming data packet.
*/
typedef struct
{
else
{
length = CA_SUPPORTED_BLE_MTU_SIZE;
- dataLen = CA_SUPPORTED_BLE_MTU_SIZE - CA_BLE_HEADER_SIZE - CA_BLE_LENGTH_HEADER_SIZE;
+ dataLen = CA_BLE_FIRST_SEGMENT_PAYLOAD_SIZE;
}
result = CAMakeFirstDataSegment(dataSegment,
index);
result = CAMakeRemainDataSegment(dataSegment,
+ CA_BLE_NORMAL_SEGMENT_PAYLOAD_SIZE,
bleData->data,
- CA_SUPPORTED_BLE_MTU_SIZE - CA_BLE_HEADER_SIZE,
+ bleData->dataLen,
index,
dataHeader);
OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending the last chunk");
result = CAMakeRemainDataSegment(dataSegment,
- bleData->data,
remainingLen,
+ bleData->data,
+ bleData->dataLen,
index,
dataHeader);
OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Sending the chunk number [%d]", index);
result = CAMakeRemainDataSegment(dataSegment,
+ CA_BLE_NORMAL_SEGMENT_PAYLOAD_SIZE,
bleData->data,
- CA_SUPPORTED_BLE_MTU_SIZE - CA_BLE_HEADER_SIZE,
+ bleData->dataLen,
index,
dataHeader);
OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending the last chunk");
result = CAMakeRemainDataSegment(dataSegment,
- bleData->data,
remainingLen,
+ bleData->data,
+ bleData->dataLen,
index,
dataHeader);
else
{
length = CA_SUPPORTED_BLE_MTU_SIZE;
- dataLen = CA_SUPPORTED_BLE_MTU_SIZE - CA_BLE_HEADER_SIZE - CA_BLE_LENGTH_HEADER_SIZE;
+ dataLen = CA_BLE_FIRST_SEGMENT_PAYLOAD_SIZE;
}
result = CAMakeFirstDataSegment(dataSegment,
for (index = 0; index < iter; index++)
{
result = CAMakeRemainDataSegment(dataSegment,
+ CA_BLE_NORMAL_SEGMENT_PAYLOAD_SIZE,
bleData->data,
- CA_SUPPORTED_BLE_MTU_SIZE - CA_BLE_HEADER_SIZE,
+ bleData->dataLen,
index,
dataHeader);
OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending the last chunk");
result = CAMakeRemainDataSegment(dataSegment,
- bleData->data,
remainingLen,
+ bleData->data,
+ bleData->dataLen,
index,
dataHeader);
for (index = 0; index < iter; index++)
{
result = CAMakeRemainDataSegment(dataSegment,
+ CA_BLE_NORMAL_SEGMENT_PAYLOAD_SIZE,
bleData->data,
- CA_SUPPORTED_BLE_MTU_SIZE - CA_BLE_HEADER_SIZE,
+ bleData->dataLen,
index,
dataHeader);
OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending the last chunk");
result = CAMakeRemainDataSegment(dataSegment,
- bleData->data,
remainingLen,
+ bleData->data,
+ bleData->dataLen,
index,
dataHeader);
else
{
length = CA_SUPPORTED_BLE_MTU_SIZE;
- dataOnlyLen = CA_SUPPORTED_BLE_MTU_SIZE - CA_BLE_HEADER_SIZE - CA_BLE_LENGTH_HEADER_SIZE;
+ dataOnlyLen = CA_BLE_FIRST_SEGMENT_PAYLOAD_SIZE;
}
result = CAMakeFirstDataSegment(dataSegment,
for (uint32_t iter = 0; iter < dataLimit; iter++)
{
result = CAMakeRemainDataSegment(dataSegment,
+ CA_BLE_NORMAL_SEGMENT_PAYLOAD_SIZE,
data,
- CA_SUPPORTED_BLE_MTU_SIZE - CA_BLE_HEADER_SIZE,
+ dataLen,
iter,
dataHeader);
OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending the last chunk");
result = CAMakeRemainDataSegment(dataSegment,
- data,
remainingLen,
+ data,
+ dataLen,
dataLimit,
dataHeader);
m_resourceUri = resourceURI;
- OCPlatform::registerResource(m_resourceHandle, resourceURI, resourceTypeName,
- resourceInterface,
- nullptr,
- OC_DISCOVERABLE);
+ OCStackResult ret = OCPlatform::registerResource(m_resourceHandle,
+ resourceURI,
+ resourceTypeName,
+ resourceInterface,
+ nullptr,
+ OC_DISCOVERABLE);
+
+ if (OC_STACK_OK != ret)
+ {
+ cout << "Resource creation was unsuccessful\n";
+ return;
+ }
m_publishedResourceHandles.push_back(m_resourceHandle);
cout << "registerResource is called." << endl;