Docs

You are here:
Block transfers

Using message filters

The following example illustrates the usage of a block transfer:

#include "rcm.h"
#include "rcm_block_transfer_connection.h"
// Structure holding information about the RCM connection
static RCMConnection rcm;
// Structure holding information about the block transfer connection
static RCMBTConnection rcmbtConnection;
static SCOM_DECLARE_FRAME_BUFFER_USING_HEAP(frameBufferInHeap);
static RCM_DECLARE_MESSAGE_BUFFER_USING_HEAP(messageBufferInHeap);
static RCMBT_DECLARE_TRANSFER_BUFFER_USING_HEAP(blockTransferBuff);
uint8_t dataToSend[8*1024];
void dataReceptionCallback(RCMBTConnection* rcmbt, RCMBTTransfer* transferEntry, void* data, size_t size)
{
DIAG0_LogMsg(0, "DATA RECEPTION CALLBACK: transfer ID: ");
DIAG0_LogUINT(0, transferEntry->transferID, 10);
DIAG0_LogMsg(0, " received ");
DIAG0_LogUINT64(0, size, 10);
DIAG0_LogMsg(0, " bytes.");
DIAG0_LogNL(0);
}
void transferFinishedCallback(RCMBTConnection* rcmbt, RCMBTTransfer* transferEntry)
{
DIAG0_LogMsg(0, "TRANSFER FINISHED CALLBACK: transfer ID: ");
DIAG0_LogUINT(0, transferEntry->transferID, 10);
DIAG0_LogMsg(0, " finished.");
DIAG0_LogNL(0);
}
int rcm_block_transfer_send_example(IODevice iodevice)
{
int result = 0;
RCMBTTransfer* transfer;
RCMAddr dstAddr;
// try to open the connection using specified IODevice
if (RCM_RESULT_OK == RCM_Open(&rcm, iodevice, &frameBufferInHeap, &messageBufferInHeap, OS_GetSystemTime)) {
// connection opened, run it
if (RCM_RESULT_OK == RCM_Run(&rcm)) {
// threads run successfully
// configure the RCM module
RCM_SetUID(&rcm, 0x0123456789abcdee);
// register data endpoint 1
// establish the network
if (RCM_RESULT_OK == RCM_StartNetworking(&rcm)) {
// network established successfully
// initialize a block transfer connection on top of the RCM connection using endpoint 1
if (RCM_RESULT_OK == RCMBT_InitTransferConnection(&rcmbtConnection, &rcm, 1, &blockTransferBuff, 3000)) {
// setup the data reception callback
RCMBT_SetDataReceptionCallback(&rcmbtConnection, (RCMBTDataReceptionCallback) dataReceptionCallback);
// setup the transfer finished callback
RCMBT_SetTransferFinishedCallback(&rcmbtConnection, (RCMBTTransferFinishedCallback) transferFinishedCallback);
// run the block transfer connection
if (RCM_RESULT_OK == RCMBT_RunTransferConnection(&rcmbtConnection)) {
// block transfer is running
// schedule an outgoing block transfer
dstAddr.shortAddr = 0;
if (RCM_RESULT_OK == RCMBT_SendTransfer(&rcmbtConnection, &dstAddr, RCM_ADDR_MODE_SHORT_ADDRESS, 1, dataToSend, sizeof(dataToSend), &transfer)) {
// wait for transfer finish
} else {
// error
result = 6;
}
// stop transfer connection
RCMBT_StopTransferConnection(&rcmbtConnection);
} else {
// error
result = 5;
}
} else {
// error
result = 4;
}
// close network
} else {
// error
result = 3;
}
// stop the RCM threads
RCM_Stop(&rcm);
} else {
// error
result = 2;
}
// finally close the connection
RCM_Close(&rcm);
} else {
// error
result = 1;
}
return result;
}
Go to Top