大家好!
我们正在使用专有协议远距离5kbps ..一些基本问题我有关于选择
1.如果发送的数据包超过255字节,它正在抛出一些 error...please 建议
我们的要求要求一次发送1024字节的数据包大小、请建议..
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
大家好!
我们正在使用专有协议远距离5kbps ..一些基本问题我有关于选择
1.如果发送的数据包超过255字节,它正在抛出一些 error...please 建议
我们的要求要求一次发送1024字节的数据包大小、请建议..
要传输长度字节大于255的数据包、需要使用高级 TX 命令。
当您没有分享您正在做的事情时、无法判断您在做什么错。
示例:
#define PAYLOAD_LENGTH 1024 #define SIZE_OF_LENGHT_FIELD 2 #define PACKET_INTERVAL 500000 static RF_Object rfObject; static RF_Handle rfHandle; static uint8_t packet[PAYLOAD_LENGTH + SIZE_OF_LENGHT_FIELD]; static uint16_t seqNumber; void *mainThread(void *arg0) { RF_Params rfParams; RF_Params_init(&rfParams); RF_cmdPropTxAdv.pktLen = PAYLOAD_LENGTH + SIZE_OF_LENGHT_FIELD; // For the advanced TX command, pktLen must cover length + payload RF_cmdPropTxAdv.pPkt = packet; RF_cmdPropTxAdv.startTrigger.triggerType = TRIG_NOW; RF_cmdPropTxAdv.condition.rule = 1; RF_cmdPropTxAdv.pktConf.bUseCrc = 1; rfHandle = RF_open(&rfObject, &RF_prop, (RF_RadioSetup*)&RF_cmdPropRadioDivSetup, &rfParams); RF_postCmd(rfHandle, (RF_Op*)&RF_cmdFs, RF_PriorityNormal, NULL, 0); while(1) { uint16_t j; uint8_t i = 0; // For the advanced TX command, the length must manually be written to the packet packet[i++] = (uint8_t)(PAYLOAD_LENGTH >> 8); packet[i++] = (uint8_t)(PAYLOAD_LENGTH); packet[i++] = (uint8_t)(seqNumber >> 8); packet[i++] = (uint8_t)(seqNumber++); for (j = i; j < PAYLOAD_LENGTH + SIZE_OF_LENGHT_FIELD; j++) { packet[j] = j - i + 1; } RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropTxAdv, RF_PriorityNormal, NULL, 0); RF_yield(rfHandle); usleep(PACKET_INTERVAL); } }
Siri
TX 代码...
#define PAYLOAD_LENGTH 1024
#define size_of_lenight_field 2
#define packet_interval 500000
静态 RF_Object rfObject;
静态 rf_handle rfHandle;
静态 uint8_t packet[PAYLOAD_LENGTH + size_of_lenight_field];
静态 uint16_t seqNumber;
char adxL_Data_x[200];
void *mainThread (void *arg0)
{
RF_Params rfParams;
rf_params_init (&rfParams);
RF_cmdPropTxAdv.pktLen = PAYLOAD_LENGTH + SIZE_OF_LENT_FIELD;//对于高级 TX 命令,pktLen 必须包含长度+负载
rf_cmdPropTxAdv.pPkt=数据包;
RF_cmdPropTxAdv.startTrigg.triggerType = trig_now;
RF_cmdPropTxAdv.condition.rule = 1;
rf_cmdPropTxAdv.pktConf.bUseCrc = 1;
// rf_cmdPropTx.pktConf.bUseCrc = 1;
sprintf (ADXL_Data_x、"ADVANCE \r\n");
rfHandle = rf_open (&rfObject、&rf_prop、(RF_RadioSetup*)&RF_cmdPropRadioDivSetup、&rfParams);
RF_postCmd (rfHandle、(RF_Op*)和 RF_cmdfs、RF_PriorityNormal、NULL、0);
while (1)
{
GPIO_WRITE (CONFIG_GPIO_GLED、CONFIG_GPIO_LED_ON);
uint16_t highStrLen = strlen (ADXL_Data_x);
memcpy (packet + 2、ADXL_Data_x、highStrLen);
RF_cmdPropTxAdv.pktLen = highStrLen;
RF_EventMask terminationReason = RF_runCmd (rfHandle、(RF_Op*)&RF_cmdPropTxAdv、
RF_PriorityNormal、NULL、0);
GPIO_WRITE (CONFIG_GPIO_GLED、CONFIG_GPIO_LED_OFF);
#ifndef power_measurement
// GPIO_toggle (CONFIG_GPIO_GLED);
#endif
/*关闭对讲机*/
rf_yield (rfHandle);
#ifdef power_measurement
/* packet_interval 的睡眠*/
睡眠(packet_interval);
#else
/* packet_interval us 的睡眠*/
usleep (packet_interval);
#endif
}
}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
RX 代码...我们将使用射频 UART 桥接器、这样我们就可以在 UART 终端中看到数据
/*数据包 RX 配置*/
#define DATA_ENTRY_HEADER_SIZE 8 /*通用数据条目的恒定标头大小*/
#define MAX_LENGTH 1024 /*对讲机将接受的最大长度字节*/
#define NUM_DATA_ENTRIES 2 /*注:目前仅支持两个数据条目*/
#define NUM_APTERD_BYTES 2 /*数据条目数据字段将包含:
* 1个标头字节(rf_cmdPropRx.rxConf.bIncludeHdr = 0x1)
*最多30个有效载荷字节
* 1个状态字节(rf_cmdPropRx.rxConf.bAppendStatus = 0x1)*/
#define no_packet 0
#define packet_received 1
/***** 全局变量声明......* /
静态 RF_Object rfObject;
静态 rf_handle rfHandle;
RF_CmdHandle rfPostHandle;
UART2_Handle UART;
UART2_Params uartParams;
静态字符输入[MAX_LENGTH];
int32_t UARTwrite_semStatus;
INT_fast16_t status = UART2_STATUS_SUCCESS;
volatile uint8_t packetRxCb;
Volatile size_t bytesReadCount;
/*包含用于接收数据的所有数据条目的缓冲区。
*需要编译指示来确保该缓冲区是4字节对齐的(射频内核的要求)*/
#if defined (__TI_Compiler_version__)
#pragma DATA_align (rxDataEntryBuffer、4);
静态 uint8_t
rxDataEntryBuffer[RF_Queue_data_entry_buffer_size (NUM_DATA_entries、
max_length、
num_added_bytes)];
#Elif Defined (__IAR_systems_ICC__)
#pragma DATA_alignment = 4
静态 uint8_t
rxDataEntryBuffer[RF_Queue_data_entry_buffer_size (NUM_DATA_entries、
max_length、
num_added_bytes)];
#Elif 已定义(_ GNU _)
静态 uint8_t
rxDataEntryBuffer[RF_Queue_data_entry_buffer_size (NUM_DATA_entries、
max_length、
num_added_bytes)]
__attribute__(aligned (4));
#else
此编译器不受支持。
#endif
/*针对射频内核接收 dataQueue 以填充数据*/
静态 dataQueue_t dataQueue;
静态 RFC_dataEntryGeneral_t*当前数据项;
静态 uint16_t packetLength;
静态 uint16_t* packetDataPointer;
静态 uint8_t packet[MAX_LENGTH + NUM_APTERD_BYTE - 1];/*长度字节存储在单独的变量中*/
/***** 函数定义***** /
静态 void ReceivedOnRFcallback (RF_Handle h、RF_CmdHandle ch、RF_EventMask e);
静态 void ReceiveonUARTcallback (UART2_Handle handle、void *buffer、size_t count、void *userArg、int_fast16_t status);
void *mainThread (void *arg0)
{
packetRxCb = no_packet;
RF_Params rfParams;
rf_params_init (&rfParams);
if (RFQueue_defineQueue (&dataQueue、
rxDataEntryBuffer、
sizeof (rxDataEntryBuffer)、
num_data_entries、
max_length + NUM_added_bytes))
{
/*无法为所有数据条目分配空间*/
while (1);
}
GPIO_setConfig (CONFIG_GPIO_RLED、GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
GPIO_WRITE (CONFIG_GPIO_RLED、CONFIG_GPIO_LED_OFF);
GPIO_setConfig (CONFIG_GPIO_GLED、GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
GPIO_WRITE (CONFIG_GPIO_GLED、CONFIG_GPIO_LED_OFF);
/*修改设置,使其能够执行 RX*/
/*为接收的数据设置数据实体队列*/
RF_cmdPropRxAdv.pQueue =&dataQueue;
/*丢弃 Rx 队列中忽略的数据包*/
rf_cmdPropRxAdv.rxConf.bAutoFlushIgnored = 1;
/*从 Rx 队列中丢弃具有 CRC 错误的数据包*/
rf_cmdPropRxAdv.rxConf.bAutoFlushCrcErr = 1;
/*实施数据包长度过滤以避免 PROP_ERROR_RXBUF */
RF_cmdPropRxAdv.maxPktLen = MAX_LENGTH;
RF_cmdPropRxAdv.pktConf.bRepeatOk = 1;
RF_cmdPropRxAdv.pktConf.bRepeatNok = 1;
rf_cmdPropTxAdv.pPkt=数据包;
RF_cmdPropTxAdv.startTrigg.triggerType = trig_now;
/*设置通过 UART 读取的最大字节数*/
size_t bytesToRead = MAX_LENGTH;
bytesReadCount = 0;
/*使用回调读取模式初始化 UART */
UART2_Params_init (&uartParams);
uartParams.baudrate = 115200;
uartParams.readMode = UART2_Mode_callback;
uartParams.readCallback = ReceiveonUARTcallback;
uartParams.readReturnMode = UART2_ReadReturnMode_partial;
/*访问 UART */
UART = UART2_OPEN (CONFIG_UART2_0、&uartParams);
/*打印到程序已启动的终端*/
const char startMsg[]="\r\nrf-uart 网桥已启动:\r\n";
UART2_WRITE (UART、startMsg、sizeof (startMsg)、NULL);
/*请求访问对讲机*/
rfHandle = rf_open (&rfObject、&rf_prop、(RF_RadioSetup*)&RF_cmdPropRadioDivSetup、&rfParams);
/*设置频率*/
RF_postCmd (rfHandle、(RF_Op*)和 RF_cmdfs、RF_PriorityNormal、NULL、0);
rfPostHandle = RF_postCmd (rfHandle、(RF_Op*)&RF_cmdPropRxAdv、
RF_PriorityNormal、ReceivedOnRFcallback、
RF_EventRxEntryDone);
UART2_READ (UART、&input、bytesToRead、NULL);
while (1)
{
/*检查是否已通过 RF 接收到任何内容*/
if (packetRxCb)
{
memcpy (输入、数据包、(packetLength));
size_t bytesWritten = 0;
while (bytesWritten =>= 0)
{
状态= UART2_WRITE (UART、&INPUT、packetLength、&bytesWritten);
如果(status!= UART2_STATUS_SUCCESS)
{
/* UART2_WRITE ()失败*/
while (1);
}
}
/*重置 RF RX 回调标志*/
packetRxCb = no_packet;
}
/*检查是否通过 UART*/
如果(bytesReadCount!= 0)
{
/*数据包长度设置为
* UART2_READ ()读取的字节*/
RF_cmdPropTxAdv.pktLen = bytesReadCount;
INT I;
对于(I=0;I<bytesReadCount;I++)
{
uint8_t* buffer8 =(uint8_t*)输入;
packet[i]= buffer8[i];
}
/*取消正在进行的命令*/
rf_cancelCmd (rfHandle、rfPostHandle、1);
/*发送数据包*/
RF_runCmd (rfHandle、(RF_Op*)和 RF_cmdPropTxAdv、RF_PriorityNormal、NULL、0);
/*切换绿色 LED 以指示 TX */
GPIO_TOGGLE (CONFIG_GPIO_GLED);
/*恢复 RF RX */
rfPostHandle = RF_postCmd (rfHandle、(RF_Op*)&RF_cmdPropRxAdv、
RF_PriorityNormal、ReceivedOnRFcallback、
RF_EventRxEntryDone);
bytesReadCount = 0;
/*恢复 UART 读取*/
状态= UART2_READ (UART、&input、bytesToRead、NULL);
}
}
}
/*通过射频接收数据时调用的回调函数
*函数复制变量包中的数据,并设置 packetRxCb */
void ReceivedOnRFcallback (RF_Handle h、RF_CmdHandle ch、RF_EventMask e)
{
IF (E 和 RF_EventRxEntryDone)
{
GPIO_TOGGLE (CONFIG_GPIO_RLED);
/*获取当前未处理的数据条目*/
currentDataEntry = RFQueue_getDataEntry ();//从条目加载数据
/*处理数据包数据,位于¤tDataEntry -> data:
*-长度是当前配置的第一个字节
*-数据从第二个字节开始*/
packetLength =*(uint8_t*)(¤tDataEntry -> data);//获取数据包长度(与数据包一起发送)
packetDataPointer =(uint8_t*)(¤tDataEntry -> data + 1);//数据从第二个字节开始
/*将有效负载+状态字节复制到数据包变量*/
memcpy (packet、packetDataPointer、(packetLength + 1));
/*将读取条目指针移动到下一个条目*/
RFQueue_nextEntry();
packetRxCb = packet_received;
}
}
/*通过 UART 接收数据时调用的回调函数*/
void ReceiveonUARTcallback (UART2_Handle handle、void *buffer、size_t count、void *userArg、int_fast16_t 状态)
{
如果(status!= UART2_STATUS_SUCCESS)
{
/* UART2_READ()中发生 RX 错误*/
while (1){}
}
bytesReadCount =计数;
}
你好,Siri
我们在现有的 Rx 代码中做了一些更改(使用了您在 E2E 中发布的示例),通过一个单线更改帮助了我们。 同样被张贴 在这里...
RX 代码
/*数据包 RX 配置*/
#define DATA_ENTRY_HEADER_SIZE 8 /*通用数据条目的恒定标头大小*/
#define MAX_LENGTH 320 /*对讲机将接受的最大长度字节*/
#define NUM_DATA_ENTRIES 2 /*注:目前仅支持两个数据条目*/
#define NUM_APTERD_BYTES 1+2 /*数据条目数据字段将包含:
* 1标头字节(rf_cmdPropRxAdv.rxConf.bIncludeHdr = 0x1)
*最多30个有效载荷字节
* 1个状态字节(rf_cmdPropRxAdv.rxConf.bAppendStatus = 0x1)*/
/***** 原型***** /
静态空回调(RF_Handle h、RF_CmdHandle ch、RF_EventMask e);
/***** 变量声明***** /
静态 RF_Object rfObject;
静态 rf_handle rfHandle;
/*包含用于接收数据的所有数据条目的缓冲区。
*需要编译指示来确保该缓冲区是4字节对齐的(射频内核的要求)*/
#if defined (__TI_Compiler_version__)
#pragma DATA_align (rxDataEntryBuffer、4);
静态 uint8_t
rxDataEntryBuffer[RF_Queue_data_entry_buffer_size (NUM_DATA_entries、
max_length、
num_added_bytes)];
#Elif Defined (__IAR_systems_ICC__)
#pragma DATA_alignment = 4
静态 uint8_t
rxDataEntryBuffer[RF_Queue_data_entry_buffer_size (NUM_DATA_entries、
max_length、
num_added_bytes)];
#Elif 已定义(_ GNU _)
静态 uint8_t
rxDataEntryBuffer[RF_Queue_data_entry_buffer_size (NUM_DATA_entries、
max_length、
num_added_bytes)]
__attribute__(aligned (4));
#else
此编译器不受支持。
#endif
/*针对射频内核接收 dataQueue 以填充数据*/
静态 dataQueue_t dataQueue;
静态 RFC_dataEntryGeneral_t*当前数据项;
静态 uint16_t packetLength;
静态 uint8_t* packetDataPointer;
静态 uint8_t packet[MAX_LENGTH + NUM_APTERD_BYTE - 2];/*长度字节存储在单独的变量中*/
/***** 函数定义***** /
void *mainThread (void *arg0)
{
RF_Params rfParams;
rf_params_init (&rfParams);
GPIO_setConfig (CONFIG_GPIO_RLED、GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
GPIO_WRITE (CONFIG_GPIO_RLED、CONFIG_GPIO_LED_OFF);
if (RFQueue_defineQueue (&dataQueue,
rxDataEntryBuffer、
sizeof (rxDataEntryBuffer)、
num_data_entries、
max_length + NUM_added_bytes))
{
/*无法为所有数据条目分配空间*/
while (1);
}
/*根据应用需求修改 CMD_PROP_RX 命令*/
/*为接收的数据设置数据实体队列*/
RF_cmdPropRxAdv.pQueue =&dataQueue;
/*丢弃 Rx 队列中忽略的数据包*/
rf_cmdPropRxAdv.rxConf.bAutoFlushIgnored = 1;
/*从 Rx 队列中丢弃具有 CRC 错误的数据包*/
rf_cmdPropRxAdv.rxConf.bAutoFlushCrcErr = 1;
/*实施数据包长度过滤以避免 PROP_ERROR_RXBUF */
RF_cmdPropRxAdv.maxPktLen = MAX_LENGTH;
RF_cmdPropRxAdv.pktConf.bRepeatOk = 1;
RF_cmdPropRxAdv.endTrigger.triggerType = 0x1;
/*请求访问对讲机*/
#IF 已定义(DeviceFamily_CC26X0R2)
rfHandle = rf_open (&rfObject、&rf_prop、(RF_RadioSetup*)&RF_cmdPropRadioSetup、&rfParams);
#else
rfHandle = rf_open (&rfObject、&rf_prop、(RF_RadioSetup*)&RF_cmdPropRadioDivSetup、&rfParams);
#endif//设备系列_CC26X0R2
/*设置频率*/
RF_postCmd (rfHandle、(RF_Op*)和 RF_cmdfs、RF_PriorityNormal、NULL、0);
/*进入 RX 模式并永久处于 RX 状态*/
RF_EventMask terminationReason = RF_runCmd (rfHandle、(RF_Op*)&RF_cmdPropRxAdv、
RF_PriorityNormal、回调(&R)、
RF_EventRxEntryDone);
while (1);
}
空回调(RF_Handle h、RF_CmdHandle ch、RF_EventMask e)
{
IF (E 和 RF_EventRxEntryDone)
{
GPIO_TOGGLE (CONFIG_GPIO_RLED);
/*获取当前未处理的数据条目*/
currentDataEntry = RFQueue_getDataEntry ();
/*处理数据包数据,位于¤tDataEntry -> data:
*-长度是当前配置的第一个字节
*-数据从第二个字节开始*/
packetLength =(((uint16_t)(*(uint8_t*)(¤tDataEntry->data + 1))<< 8)|
(uint16_t)(*(uint8_t*)(¤tDataEntry -> data));
packetDataPointer =(uint8_t*)(¤tDataEntry -> data + 2);
/*将有效载荷和状态字节复制到数据包变量*/
memcpy (packet、packetDataPointer、(packetLength + NUM_APTERD_BYTES - 2);
printf ("%x\r\n"、packet);
RFQueue_nextEntry();
}
}
我看不到您已经进行了任何更改来支持2字节长长度字段。
我还强烈建议您将 rfPacketRX 示例作为起点、并在开始将任何其他外设包括在示例中之前使这些示例有效。
在做一些测试时、我意识到标头的解读会因使用正常的50kbps PHY 或 SLR PHY 而不同。
以下代码使 TX 和 RX 能够使用 SLR 发送和接收1024字节长的数据包(请注意、TX 与我在上面发布的内容略有不同)
发送:
/* Packet TX Configuration */ #define PAYLOAD_LENGTH 1024 // Max 255 if SIZE_OF_LENGHT_FIELD = 1 #define SIZE_OF_LENGHT_FIELD 2 #define PACKET_INTERVAL 500000 /* Set packet interval to 500000 us or 500 ms */ /***** Prototypes *****/ /***** Variable declarations *****/ static RF_Object rfObject; static RF_Handle rfHandle; static uint8_t packet[PAYLOAD_LENGTH + SIZE_OF_LENGHT_FIELD]; static uint16_t seqNumber; /***** Function definitions *****/ void *mainThread(void *arg0) { RF_Params rfParams; RF_Params_init(&rfParams); GPIO_setConfig(CONFIG_GPIO_GLED, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW); GPIO_write(CONFIG_GPIO_GLED, CONFIG_GPIO_LED_OFF); RF_cmdPropTxAdv.pktLen = PAYLOAD_LENGTH + SIZE_OF_LENGHT_FIELD; // For the advanced TX command, pktLen must cover length + payload RF_cmdPropTxAdv.pPkt = packet; RF_cmdPropTxAdv.startTrigger.triggerType = TRIG_NOW; RF_cmdPropTxAdv.condition.rule = 1; // Not set in sysConfig like for the RF_cmdPropTx RF_cmdPropTxAdv.pktConf.bUseCrc = 1; // Not set in sysConfig like for the RF_cmdPropTx /* Request access to the radio */ rfHandle = RF_open(&rfObject, &RF_prop, (RF_RadioSetup*)&RF_cmdPropRadioDivSetup, &rfParams); /* Set the frequency */ RF_postCmd(rfHandle, (RF_Op*)&RF_cmdFs, RF_PriorityNormal, NULL, 0); while(1) { uint16_t j; uint8_t i = 0; // For the advanced TX command, the length must manually be written to the packet if (SIZE_OF_LENGHT_FIELD == 1) { packet[i++] = (uint8_t)(PAYLOAD_LENGTH); } else // SIZE_OF_LENGHT_FIELD = 2 { // Normal PHY //packet[i++] = (uint8_t)(PAYLOAD_LENGTH >> 8); //packet[i++] = (uint8_t)(PAYLOAD_LENGTH); // SLR PHY packet[i++] = (uint8_t)(PAYLOAD_LENGTH); packet[i++] = (uint8_t)(PAYLOAD_LENGTH >> 8); } packet[i++] = (uint8_t)(seqNumber >> 8); packet[i++] = (uint8_t)(seqNumber++); for (j = i; j < PAYLOAD_LENGTH + SIZE_OF_LENGHT_FIELD; j++) { packet[j] = j - i + 1; } /* Send packet */ RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropTxAdv, RF_PriorityNormal, NULL, 0); GPIO_toggle(CONFIG_GPIO_GLED); /* Power down the radio */ RF_yield(rfHandle); /* Sleep for PACKET_INTERVAL us */ usleep(PACKET_INTERVAL); } }
接收:
/* Packet RX Configuration */ #define DATA_ENTRY_HEADER_SIZE 8 /* Constant header size of a Generic Data Entry */ #define MAX_LENGTH 1024 /* Max length byte the radio will accept */ /* Must be less than 256 if SIZE_OF_LENGHT_FIELD = 1 */ #define NUM_DATA_ENTRIES 2 /* NOTE: Only two data entries supported at the moment */ #define SIZE_OF_LENGHT_FIELD 2 #define NUM_APPENDED_BYTES 1 + SIZE_OF_LENGHT_FIELD /* The Data Entries data field will contain: * 1 or 2 header byte(s) (containing the length) * A maximum of MAX_LENGTH payload bytes * 1 status byte (RF_cmdPropRxAdv.rxConf.bAppendStatus = 0x1) */ /***** Prototypes *****/ static void callback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e); /***** Variable declarations *****/ static RF_Object rfObject; static RF_Handle rfHandle; /* Buffer which contains all Data Entries for receiving data. * Pragmas are needed to make sure this buffer is 4 byte aligned (requirement from the RF Core) */ #if defined(__TI_COMPILER_VERSION__) #pragma DATA_ALIGN (rxDataEntryBuffer, 4); static uint8_t rxDataEntryBuffer[RF_QUEUE_DATA_ENTRY_BUFFER_SIZE(NUM_DATA_ENTRIES, MAX_LENGTH, NUM_APPENDED_BYTES)]; #elif defined(__IAR_SYSTEMS_ICC__) #pragma data_alignment = 4 static uint8_t rxDataEntryBuffer[RF_QUEUE_DATA_ENTRY_BUFFER_SIZE(NUM_DATA_ENTRIES, MAX_LENGTH, NUM_APPENDED_BYTES)]; #elif defined(__GNUC__) static uint8_t rxDataEntryBuffer[RF_QUEUE_DATA_ENTRY_BUFFER_SIZE(NUM_DATA_ENTRIES, MAX_LENGTH, NUM_APPENDED_BYTES)] __attribute__((aligned(4))); #else #error This compiler is not supported. #endif /* Receive dataQueue for RF Core to fill in data */ static dataQueue_t dataQueue; static rfc_dataEntryGeneral_t* currentDataEntry; static uint16_t packetLength; static uint8_t* packetDataPointer; static rfc_propRxOutput_t rxStatistics; static uint8_t packet[MAX_LENGTH + NUM_APPENDED_BYTES]; /***** Function definitions *****/ void *mainThread(void *arg0) { RF_Params rfParams; RF_Params_init(&rfParams); GPIO_setConfig(CONFIG_GPIO_RLED, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW); GPIO_write(CONFIG_GPIO_RLED, CONFIG_GPIO_LED_OFF); if( RFQueue_defineQueue(&dataQueue, rxDataEntryBuffer, sizeof(rxDataEntryBuffer), NUM_DATA_ENTRIES, MAX_LENGTH + NUM_APPENDED_BYTES)) { /* Failed to allocate space for all data entries */ while(1); } /* Modify CMD_PROP_RX command for application needs */ /* Set the Data Entity queue for received data */ RF_cmdPropRxAdv.pQueue = &dataQueue; /* Discard ignored packets from Rx queue */ RF_cmdPropRxAdv.rxConf.bAutoFlushIgnored = 1; /* Discard packets with CRC error from Rx queue */ RF_cmdPropRxAdv.rxConf.bAutoFlushCrcErr = 1; /* Implement packet length filtering to avoid PROP_ERROR_RXBUF */ RF_cmdPropRxAdv.maxPktLen = MAX_LENGTH; RF_cmdPropRxAdv.pktConf.bRepeatOk = 1; RF_cmdPropRxAdv.pktConf.bRepeatNok = 1; RF_cmdPropRxAdv.pOutput = (uint8_t*)&rxStatistics; RF_cmdPropRxAdv.condition.rule = 1; RF_cmdPropRxAdv.pktConf.bUseCrc = 0x1; RF_cmdPropRxAdv.rxConf.bIncludeHdr = 0x1; RF_cmdPropRxAdv.rxConf.bAppendStatus = 0x1; RF_cmdPropRxAdv.endTrigger.triggerType = 0x1; RF_cmdPropRxAdv.pktConf.bCrcIncHdr = 0x1; // Field specific for the advanced RX command if (SIZE_OF_LENGHT_FIELD == 1) { RF_cmdPropRxAdv.hdrConf.numHdrBits = 8; // Field specific for the advanced RX command RF_cmdPropRxAdv.hdrConf.numLenBits = 8; // Field specific for the advanced RX command } else // SIZE_OF_LENGHT_FIELD = 2 { RF_cmdPropRxAdv.hdrConf.numHdrBits = 16;// Field specific for the advanced RX command RF_cmdPropRxAdv.hdrConf.numLenBits = 16;// Field specific for the advanced RX command } /* Request access to the radio */ rfHandle = RF_open(&rfObject, &RF_prop, (RF_RadioSetup*)&RF_cmdPropRadioDivSetup, &rfParams); /* Set the frequency */ RF_postCmd(rfHandle, (RF_Op*)&RF_cmdFs, RF_PriorityNormal, NULL, 0); /* Enter RX mode and stay forever in RX */ RF_EventMask terminationReason = RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropRxAdv, RF_PriorityNormal, &callback, RF_EventRxEntryDone); while(1); } void callback(RF_Handle h, RF_CmdHandle ch, RF_EventMask e) { if (e & RF_EventRxEntryDone) { GPIO_toggle(CONFIG_GPIO_RLED); /* Get current unhandled data entry */ currentDataEntry = RFQueue_getDataEntry(); if (SIZE_OF_LENGHT_FIELD == 1) { packetLength = *(uint8_t*)(¤tDataEntry->data); packetDataPointer = (uint8_t*)(¤tDataEntry->data + SIZE_OF_LENGHT_FIELD); /* Copy the payload + the status byte to the packet variable */ memcpy(packet, packetDataPointer, (packetLength + SIZE_OF_LENGHT_FIELD)); } else // SIZE_OF_LENGHT_FIELD = 2 { packetLength = ((uint16_t)((*(uint8_t*)(¤tDataEntry->data+1)) << 8) | (uint16_t)(*(uint8_t*)(¤tDataEntry->data))); packetDataPointer = (uint8_t*)(¤tDataEntry->data + SIZE_OF_LENGHT_FIELD); /* Copy the payload and the status bytes to the packet variable */ memcpy(packet, packetDataPointer, (packetLength + NUM_APPENDED_BYTES - SIZE_OF_LENGHT_FIELD)); } RFQueue_nextEntry(); } }
Siri