简体   繁体   English

如何将有效载荷发送到XBee

[英]How do I send a payload to an XBee

I have implemented the following code on an embedded platform that attempts to communicate with an XBee . 我已经在尝试与XBee通信的嵌入式平台上实现了以下代码。 The embedded platform that executes the code below is not an xbee: 执行以下代码的嵌入式平台不是 xbee:

int main()
{
   char payload[12] = {0x61,0x88,0x00,0x64,0x00,0x00,0x00,0x00,0x00,0xEC,0x00,0x00}
   payload[2] = 0x10;
   payload[9] = 0x01;
   char data = 'H'; // Send simple ASCII character to XBee
   payload[11]= data;

   while (1)
      sendByteofData(payload,12);
}

void sendByteOfData(char * payload, int len)
{
   int x;

   for (x=0;x<4;x++)
      // This function sends IEEE 802.15.4 frames, and I know it
      // works because they are detected in the [sniffer][3].
      send_IEEE_802_15_4_frame(payload,len);
   }

   payload[2] = payload[2] % 256 + 1;
   payload[9] = payload[9] % 256 + 1;

   if (payload[9] % 256 == 0 )
      payload[9] = 0x01;
   else
      payload[9] %= 256;
}

To my surprise the above code actually sent one byte from the embedded platform to the XBee successfully. 令我惊讶的是,以上代码实际上从嵌入式平台成功地向XBee发送了一个字节。 however, the infinite loop at the end of main() should have produced a stream of bytes. 但是,main()末尾的无限循环应该已经产生了字节流。

My suspicion is I need to set payload[2] and payload[9] correctly, and there is probably a flaw in the incremental modulo 256 algorithm shown above. 我的怀疑是我需要正确设置payload[2]payload[9] ,并且上面显示的增量模256算法可能存在缺陷。

How do I get a continuous stream of bytes? 如何获得连续的字节流?

A few thoughts... 一些想法...

  1. Make your payload an array of unsigned char or, even better, uint8_t . 使您的有效负载成为unsigned char数组,或者甚至更好的是uint8_t数组。
  2. To update payload[2] and payload[9], simplify your code: 要更新有效负载[2]和有效负载[9],请简化您的代码:

     ++payload[2]; ++payload[9]; if (payload[9] == 0) payload[9] = 1; 
  3. Add a delay between sends. 在发送之间添加延迟。 You might even need to wait for a response before sending the next character. 您甚至可能需要等待响应才能发送下一个字符。

Since it's a payload of unsigned 8-bit values, they'll automatically roll from 255 to 0. I assume your special case code for payload[9] is trying to roll from 255 to 1 (instead of 0). 由于它是无符号8位值的有效负载,因此它们会自动从255滚动到0。我假设您的有效负载[9]的特殊情况代码正在尝试从255滚动到1(而不是0)。

Make sure your payload doesn't need to include a checksum of some sort. 确保您的有效载荷不需要包含某种校验和。 Updating those two bytes would have an affect on a checksum byte. 更新这两个字节将对校验和字节产生影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM