[Tinyos-devel] Possible bug in TOS2 Sender.java

Cory Sharp cory at moteiv.com
Tue Apr 10 18:03:33 PDT 2007


I believe there may be a bug in the TinyOS 2.x Sender.java in
support/sdk/java/net/tinyos/message/.   The message length is currently
taken to be the array length from the result of m.dataGet().  I think the
actual length should probably be the result of m.dataLength().  A diff is
below.  For my particular use-case, the existing code fails and the fixed
code behaves correctly.

Cory

Index: Sender.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x
/support/sdk/java/net/tinyos/message/Sender.java,v
retrieving revision 1.4
diff -u -r1.4 Sender.java
--- Sender.java 12 Dec 2006 18:22:59 -0000      1.4
+++ Sender.java 11 Apr 2007 00:54:37 -0000
@@ -77,6 +77,7 @@
     synchronized public void send(int moteId, Message m) throws IOException
{
        int amType = m.amType();
        byte[] data = m.dataGet();
+        int length = m.dataLength();

        if (amType < 0) {
            throw new IOException("unknown AM type for message " +
@@ -84,11 +85,11 @@
        }

        SerialPacket packet =
-           new SerialPacket(SerialPacket.offset_data(0) + data.length);
+           new SerialPacket(SerialPacket.offset_data(0) + length);
        packet.set_header_dest(moteId);
        packet.set_header_type((short)amType);
-       packet.set_header_length((short)data.length);
-       packet.dataSet(data, 0, packet.offset_data(0), data.length);
+       packet.set_header_length((short)length);
+       packet.dataSet(data, 0, packet.offset_data(0), length);

        byte[] packetData = packet.dataGet();
        byte[] fullPacket = new byte[packetData.length + 1];
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.millennium.berkeley.edu/pipermail/tinyos-devel/attachments/20070410/7be73eec/attachment.html


More information about the Tinyos-devel mailing list