ZHDA134 April 2026 CC1310 , CC1311P3 , CC1312PSIP , CC1312R , CC1312R7 , CC1314R10 , CC1350 , CC1352P , CC1352P7 , CC1352R , CC1354P10 , CC1354R10
编写 rfPacketTx 示例是为了支持此格式,除了有效载荷长度和内容外,无需更改代码示例。但以下代码片段做了部分优化修改,以提升可读性。以下代码展示了如何修改 rfPacketTx.c 以实现每 0.5s 发送一次所需的有效载荷。
1: //---------------------------------------------------------------------------------------------
2: // Transmit Standard Packet Format with CMD_PROP_TX (1 Length Byte)
3: //---------------------------------------------------------------------------------------------
4:
5: // Defines
6: #define PAYLOAD_LENGTH 3 // Max 255 bytes
7:
8: uint8_t packet[PAYLOAD_LENGTH];
9:
10: static RF_Object rfObject;
11: static RF_Handle rfHandle;
12:
13: void *mainThread(void *arg0)
14: {
15: RF_Params rfParams;
16: RF_Params_init(&rfParams);
17:
18: RF_cmdPropTx.pktLen = PAYLOAD_LENGTH; // Application specific settings
19: RF_cmdPropTx.pPkt = packet;
20:
21: rfHandle = RF_open(&rfObject, &RF_prop,
22: (RF_RadioSetup*)&RF_cmdPropRadioDivSetup, &rfParams);
23: RF_postCmd(rfHandle, (RF_Op*)&RF_cmdFs, RF_PriorityNormal, NULL, 0);
24:
25: while(1)
26: {
27: //-------------------------------------------------------------------------------------
28: // Could be placed outside the while(1) since the packet does not change
29: for (uint8_t i = 0; i < PAYLOAD_LENGTH; i++)
30: {
31: packet[i] = i + 1;
32: }
33: //-------------------------------------------------------------------------------------
34: RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropTx, RF_PriorityNormal, NULL, 0);
35: RF_yield(rfHandle);
36: usleep(500000);
37: }
38: }使用标准 TX 命令时,最大有效载荷长度为 255,并且长度字节 (PAYLOAD_LENGTH) 必须写入命令的.pktLen 字段。